Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / YinStatementParserImpl.java
index d72c644415cdd8aac2513551af0ec905aeb0a358..4ce9bce6499a333fbb6538e611dd97dcff9f342b 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
@@ -147,8 +148,7 @@ public class YinStatementParserImpl {
                 if (identifier.equals(Rfc6020Mapping.TYPE.getStatementName())) {
                     isType = true;
                 } else {
-                    startStatement(QName.create(validStatementDefinition.getModule(), getElementFullName
-                            (inputReader)),  ref);
+                    startStatement(validStatementDefinition, ref);
                     if (isStatementWithYinElement(identifier, stmtDef)) {
                         action = false;
                     }
@@ -156,8 +156,8 @@ public class YinStatementParserImpl {
             } else {
                 //if statement not found through all phases, throw exception
                 if (writer.getPhase().equals(ModelProcessingPhase.FULL_DECLARATION)) {
-                    throw new IllegalArgumentException(identifier.getLocalName() + " is not a YIN " +
-                            "statement or use of extension. Source: " + ref);
+                    throw new SourceException(String.format("%s is not a YIN statement or use of extension.",
+                            identifier.getLocalName()), ref);
                 } else {
                     //otherwise skip it (statement not to be read yet)
                     action = false;