Add/improve yang parser error reporting 66/27866/9
authorTom Pantelis <tpanteli@brocade.com>
Fri, 2 Oct 2015 16:18:50 +0000 (12:18 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 9 Nov 2015 11:48:54 +0000 (11:48 +0000)
commite27979870db1358da1477c6d13b05c510c2045d8
treec1fc6154039e0a7ebe743f6fbdadda2ffd09adb2
parentddd133e9f4efa05ba87230a598c9f015e2985c0a
Add/improve yang parser error reporting

If a yang file fails to load/parse in karaf, it fails silently. The
first problem is that YangTextSchemaContextResolver#getSchemaContext
logs the SchemaResolutionException to debug as it retries with
getResolvedSources. But if getResolvedSources is empty, it ends up
silently returning an empty SchemaContext.

Another issue is that the underlying exceptions that are really relevant
are added as suppressed to the aggregating exception. This would be fine
if the underlying logger in karaf printed suppressed exceptions as
Throwable#printStackTrace does but it doesn't. The suppressed exceptions
do appear from maven (that underlying logger uses printStackTrace).

My first thought was to log the SchemaResolutionException if
SchemaResolutionException was empty but use printStackTrace to get the
suppressed exceptions. However there are 3 levels of exceptions which is
kind of ugly - one needs to sift thru a lot of noise and long stack
traces to find the relevant error.

So. to make it more user-friendly, I instead modified BundleGlobalContext
to log each source exception's suppressed exceptions as these contain the
actual parsing failures. I also only printed the exception message
normally to avoid the stack trace noise. The full trace can be seen with
debug enabled.

Change-Id: Ie603bab3caa4fabc421ffbd106fddd5176743d2b
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangStatementSourceImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserNegativeTest.java