Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / ModuleStatementSupport.java
index a6e5f0c0bd711b652915b168bb4529db37111cd6..ea6d565b895288b891582df87ec952ac5d7e319f 100644 (file)
@@ -97,8 +97,8 @@ public class ModuleStatementSupport extends
         Optional<URI> moduleNs = Optional.fromNullable(firstAttributeOf(stmt.declaredSubstatements(),
                 NamespaceStatement.class));
         if (!moduleNs.isPresent()) {
-            throw new IllegalArgumentException("Namespace of the module [" + stmt.getStatementArgument()
-                    + "] is missing.");
+            throw new SourceException(String.format("Namespace of the module [%s] is missing",
+                    stmt.getStatementArgument()), stmt.getStatementSourceReference());
         }
 
         Optional<Date> revisionDate = Optional.fromNullable(Utils.getLatestRevision(stmt.declaredSubstatements()));
@@ -116,7 +116,8 @@ public class ModuleStatementSupport extends
 
         String modulePrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
         if (modulePrefix == null) {
-            throw new IllegalArgumentException("Prefix of the module [" + stmt.getStatementArgument() + "] is missing.");
+            throw new SourceException(String.format("Prefix of the module [%s] is missing",
+                    stmt.getStatementArgument()), stmt.getStatementSourceReference());
         }
 
         stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);