Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
This adds logging for content handlers so that exceptions raised by
user-defined code can be immediately located.

Affects: #3
  • Loading branch information
io7m committed Jan 24, 2021
1 parent a45e10a commit cfd2d98
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
15 changes: 12 additions & 3 deletions README-CHANGES.xml
@@ -1,18 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<c:changelog project="com.io7m.blackthorne" xmlns:c="urn:com.io7m.changelog:4.0">
<c:releases>
<c:release date="2020-10-15T00:00:00+00:00" ticket-system="com.github.io7m.blackthorne" version="1.0.0">
<c:release date="2020-10-15T00:00:00+00:00" is-open="false" ticket-system="com.github.io7m.blackthorne" version="1.0.0">
<c:changes/>
</c:release>
<c:release date="2020-10-24T20:32:34+00:00" ticket-system="com.github.io7m.blackthorne" version="1.1.0">
<c:release date="2020-10-24T00:00:00+00:00" is-open="false" ticket-system="com.github.io7m.blackthorne" version="1.1.0">
<c:changes>
<c:change date="2020-10-24T20:32:34+00:00" summary="Allow content handlers to throw raw exceptions">
<c:change date="2020-10-24T00:00:00+00:00" summary="Allow content handlers to throw raw exceptions">
<c:tickets>
<c:ticket id="2"/>
</c:tickets>
</c:change>
</c:changes>
</c:release>
<c:release date="2021-01-24T12:38:06+00:00" is-open="true" ticket-system="com.github.io7m.blackthorne" version="1.2.0">
<c:changes>
<c:change date="2021-01-24T12:38:06+00:00" summary="Add logging for content handlers">
<c:tickets>
<c:ticket id="3"/>
</c:tickets>
</c:change>
</c:changes>
</c:release>
</c:releases>
<c:ticket-systems>
<c:ticket-system default="true" id="com.github.io7m.blackthorne" url="https://www.github.com/io7m/blackthorne/issues/"/>
Expand Down
Expand Up @@ -17,6 +17,8 @@
package com.io7m.blackthorne.api;

import com.io7m.jlexing.core.LexicalPosition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
Expand All @@ -40,6 +42,9 @@

public final class BTContentHandler<T> extends DefaultHandler2
{
private static final Logger LOG =
LoggerFactory.getLogger(BTContentHandler.class);

private final URI fileURI;
private final Consumer<BTParseError> errorReceiver;
private Locator2 locator;
Expand Down Expand Up @@ -112,8 +117,10 @@ private static String messageOrException(
public void setDocumentLocator(
final Locator in_locator)
{
this.locator = (Locator2) Objects.requireNonNull(in_locator, "locator");
this.stackHandler = new BTStackHandler<T>(this.locator, this.rootHandlers);
this.locator =
(Locator2) Objects.requireNonNull(in_locator, "locator");
this.stackHandler =
new BTStackHandler<>(this.locator, this.rootHandlers);
}

@Override
Expand Down Expand Up @@ -166,6 +173,8 @@ public void characters(
public void warning(
final SAXParseException e)
{
LOG.warn("parse exception: ", e);

this.errorReceiver.accept(
BTParseError.builder()
.setException(e)
Expand All @@ -179,6 +188,8 @@ public void warning(
public void error(
final SAXParseException e)
{
LOG.error("parse exception: ", e);

this.failed = true;
this.errorReceiver.accept(
BTParseError.builder()
Expand All @@ -194,6 +205,8 @@ public void fatalError(
final SAXParseException e)
throws SAXException
{
LOG.error("fatal parse exception: ", e);

this.failed = true;
this.errorReceiver.accept(
BTParseError.builder()
Expand Down

0 comments on commit cfd2d98

Please sign in to comment.