Provide better error messages when parsing JSON. 71/20171/4
authorColin Dixon <colin@colindixon.com>
Fri, 10 Apr 2015 00:36:49 +0000 (20:36 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 15 Jun 2015 10:55:54 +0000 (10:55 +0000)
Change-Id: Ia3a613964ce74a6179a568098b83f9d3755fb9a4
Signed-off-by: Colin Dixon <colin@colindixon.com>
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java

index f7eeff3f01bf87a365860e59ae070fd2d76c0d0d..69cfb6fea44f7a908467203b78fed2b19858c025 100644 (file)
@@ -105,7 +105,7 @@ public final class JsonParserStream implements Closeable, Flushable {
     }
 
     private final void setValue(final AbstractNodeDataWithSchema parent, final String value) {
-        Preconditions.checkArgument(parent instanceof SimpleNodeDataWithSchema, "Node %s is not a simple type", parent);
+        Preconditions.checkArgument(parent instanceof SimpleNodeDataWithSchema, "Node %s is not a simple type", parent.getSchema().getQName());
 
         final Object translatedValue = translateValueByType(value, parent.getSchema());
         ((SimpleNodeDataWithSchema) parent).setValue(translatedValue);
@@ -199,7 +199,7 @@ public final class JsonParserStream implements Closeable, Flushable {
         } else if (parent instanceof LeafListNodeDataWithSchema) {
             newChild = new LeafListEntryNodeDataWithSchema(parent.getSchema());
         } else {
-            throw new IllegalStateException("Incorrec nesting caused by parser.");
+            throw new IllegalStateException("Found an unexpected array nested under "+ parent.getSchema().getQName());
         }
         ((CompositeNodeDataWithSchema) parent).addChild(newChild);
         return newChild;
@@ -250,7 +250,7 @@ public final class JsonParserStream implements Closeable, Flushable {
             } else if (potentialUris.size() > 1) {
                 throw new IllegalStateException("Choose suitable module name for element "+nodeNamePart+":"+toModuleNames(potentialUris));
             } else if (potentialUris.isEmpty()) {
-                throw new IllegalStateException("Schema node with name "+nodeNamePart+" wasn't found.");
+                throw new IllegalStateException("Schema node with name "+nodeNamePart+" wasn't found under "+dataSchemaNode.getQName()+".");
             }
         }
 
index 4f59b16c03e0eb48cb65d249285fb0d7ff986614..0fff8ade85a115d7eec3623bfc657136d3d721a8 100644 (file)
@@ -207,7 +207,7 @@ public class JsonStreamToNormalizedNodeTest {
             //second parameter isn't necessary because error will be raised before it is used.
             verifyTransformationToNormalizedNode(inputJson, null);
         } catch (final IllegalStateException e) {
-            assertTrue(e.getMessage().contains("Schema node with name dummy-element wasn't found."));
+            assertTrue(e.getMessage().contains("Schema node with name dummy-element wasn't found"));
         }
     }