Skip to content

Commit

Permalink
Improve error logging for unrecognized elements
Browse files Browse the repository at this point in the history
This prints a message at the point of error, and prints the entire
handler stack.

Fix: #3
  • Loading branch information
io7m committed Aug 8, 2023
1 parent 1781345 commit fc26e3e
Showing 1 changed file with 39 additions and 8 deletions.
Expand Up @@ -207,14 +207,12 @@ public void onElementStarted(
return;
}
case DO_NOT_IGNORE_UNRECOGNIZED_ELEMENTS: {
throw new SAXParseException(
BTMessages.format(
"errorHandlerUnrecognizedElement",
topMostHandler.getClass().getCanonicalName(),
namespaceURI,
localName,
handlerNames(childHandlers)),
this.context.documentLocator());
throw this.errorUnrecognizedElement(
namespaceURI,
localName,
topMostHandler,
(Map<BTQualifiedName, BTElementHandlerConstructorType<?, ?>>) childHandlers
);
}
}
}
Expand All @@ -240,6 +238,39 @@ public void onElementStarted(
}
}

private SAXParseException errorUnrecognizedElement(
final String namespaceURI,
final String localName,
final BTElementHandlerType<?, ?> topMostHandler,
final Map<BTQualifiedName, BTElementHandlerConstructorType<?, ?>> childHandlers)
{
final var ex =
new SAXParseException(
BTMessages.format(
"errorHandlerUnrecognizedElement",
topMostHandler.getClass().getCanonicalName(),
namespaceURI,
localName,
handlerNames(childHandlers)),
this.context.documentLocator()
);

if (LOG.isDebugEnabled()) {
LOG.debug("", ex);
LOG.debug("Handler: {}", topMostHandler.name());

for (int index = 0; index < this.stack.size(); ++index) {
LOG.debug(
"Stack [{}]: {}",
Integer.valueOf(index),
this.stack.get(index).handler.name()
);
}
}

return ex;
}

/**
* Text has been received inside an element.
*
Expand Down

0 comments on commit fc26e3e

Please sign in to comment.