[PATCH] [YAML] Recover gracefully when deserializing invalid YAML input.

Andrew Tulloch andrew at tullo.ch
Wed Jul 31 11:10:12 PDT 2013



================
Comment at: unittests/Support/YAMLIOTest.cpp:1317-1318
@@ +1316,4 @@
+  {
+    Input yin("{foo:3, bar: 5}");
+    yin.setDiagHandler(suppressErrorMessages);
+    yin >> doc;
----------------
This unfortunately outputs an error message into the unit test logs, since Document.begin() is called before we setDiagHandler. 

We can convert it to 

a) optionally pass DiagHandler in the constructor,
b) lazily initialize the DocIterator,
c) explicitly initialize Input, etc.  
d) just ignore it.

Any thoughts on this?

================
Comment at: lib/Support/YAMLTraits.cpp:47
@@ -46,3 +46,3 @@
     CurrentNode(NULL) {
   DocIterator = Strm->begin();
 }
----------------
This call can potentially output errors without allowing us to set the `DiagHandler`.

================
Comment at: include/llvm/Support/YAMLTraits.h:960
@@ -960,1 +959,3 @@
+  if (!yin.setCurrentDocument())
+    return yin;
   yamlize(yin, docMap, true);
----------------
kledzik at apple.com wrote:
> Wouldn't this whole body be simpler as:
> 
>   if (yin.setCurrentDocument())
>     yamlize(yin, docMap, true);
>   return yin;
Yes, that would be simpler.  I'll update.


http://llvm-reviews.chandlerc.com/D1236



More information about the llvm-commits mailing list