BUG-7954: identify source of the offending statement 84/53184/1
authorRobert Varga <rovarga@cisco.com>
Sat, 11 Mar 2017 20:15:55 +0000 (21:15 +0100)
committerRobert Varga <rovarga@cisco.com>
Sat, 11 Mar 2017 20:15:55 +0000 (21:15 +0100)
When we have a conflicting key we should also identify where it was
populated, as that may not be immediately obvious by looking at the
module source.

Change-Id: If48cb1af73b86bd7cbf6926dfc8fe696f796a20e
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ChildSchemaNodes.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7424Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java

index f898e310a514c64e9e86edab76b08f6982974588..53d203269740daa9bbc1db2996c54fb9dfc31148 100644 (file)
@@ -54,9 +54,12 @@ public class ChildSchemaNodes<D extends DeclaredStatement<QName>, E extends Effe
         final StmtContext<?, D, E> prev = globalOrStatementSpecific(storage).putToLocalStorageIfAbsent(
             ChildSchemaNodes.class, key, value);
 
-        SourceException.throwIf(prev != null, value.getStatementSourceReference(),
-                "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared.", value.getRoot()
-                        .getStatementArgument(), key, prev != null ? prev.getStatementArgument() : null);
+        if (prev != null) {
+            throw new SourceException(value.getStatementSourceReference(),
+                "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s",
+                value.getRoot().getStatementArgument(), key, prev.getStatementArgument(),
+                prev.getStatementSourceReference());
+        }
     }
 
     private static NamespaceStorageNode globalOrStatementSpecific(final NamespaceStorageNode storage) {
index a0f4b83ebd53d52bffe31f4b25adba3ba61d27d7..6aef3cbc311d50b96cd90c4bcd68bc4f98346655 100644 (file)
@@ -20,12 +20,9 @@ public class Bug7424Test {
             StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc.yang");
             fail("Test should fail due to invalid yang model.");
         } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e
-                    .getCause()
-                    .getMessage()
-                    .startsWith(
-                            "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
-                                    + "Node name collision: '(foo?revision=1970-01-01)name' already declared."));
+            assertTrue(e.getCause().getMessage().startsWith(
+                        "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
+                        + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
         }
     }
 
@@ -35,12 +32,9 @@ public class Bug7424Test {
             StmtTestUtils.parseYangSource("/bugs/bug7424/foo-notification.yang");
             fail("Test should fail due to invalid yang model.");
         } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e
-                    .getCause()
-                    .getMessage()
-                    .startsWith(
-                            "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
-                                    + "Node name collision: '(foo?revision=1970-01-01)name' already declared."));
+            assertTrue(e.getCause().getMessage().startsWith(
+                        "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
+                        + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
         }
     }
 
@@ -50,12 +44,9 @@ public class Bug7424Test {
             StmtTestUtils.parseYangSource("/bugs/bug7424/foo-data.yang");
             fail("Test should fail due to invalid yang model.");
         } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e
-                    .getCause()
-                    .getMessage()
-                    .startsWith(
-                            "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
-                                    + "Node name collision: '(foo?revision=1970-01-01)name' already declared."));
+            assertTrue(e.getCause().getMessage().startsWith(
+                        "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
+                        + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
         }
     }
 
@@ -65,12 +56,9 @@ public class Bug7424Test {
             StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc-uses.yang");
             fail("Test should fail due to invalid yang model.");
         } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e
-                    .getCause()
-                    .getMessage()
-                    .startsWith(
-                            "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
-                                    + "Node name collision: '(foo?revision=1970-01-01)name' already declared."));
+            assertTrue(e.getCause().getMessage().startsWith(
+                        "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
+                        + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
         }
     }
 }
index 2b1143a0b74c0ca38d252702b82db1d0f4835a4a..45c74ba6b8b036c1ca74d5cf83c35250d1efeaaf 100644 (file)
@@ -151,7 +151,7 @@ public class YangParserNegativeTest {
         } catch (final ReactorException e) {
             final String expected = "Error in module 'container': cannot add '(urn:simple.container" +
                     ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
-                    ".demo?revision=1970-01-01)foo' already declared.";
+                    ".demo?revision=1970-01-01)foo' already declared";
             assertTrue(e.getCause().getMessage().contains(expected));
         }
     }
@@ -167,7 +167,7 @@ public class YangParserNegativeTest {
         } catch (final ReactorException e) {
             final String expected = "Error in module 'container-list': cannot add '(urn:simple.container" +
                     ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
-                    ".demo?revision=1970-01-01)foo' already declared.";
+                    ".demo?revision=1970-01-01)foo' already declared";
             assertTrue(e.getCause().getMessage().contains(expected));
         }
     }
@@ -183,7 +183,7 @@ public class YangParserNegativeTest {
         } catch (final ReactorException e) {
             final String expected = "Error in module 'container-leaf': cannot add '(urn:simple.container" +
                     ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
-                    ".demo?revision=1970-01-01)foo' already declared.";
+                    ".demo?revision=1970-01-01)foo' already declared";
             assertTrue(e.getCause().getMessage().contains(expected));
         }
     }
@@ -254,4 +254,4 @@ public class YangParserNegativeTest {
         }
     }
 
-}
\ No newline at end of file
+}