allow LogHandlers to break conversion throwing an exception
MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java
@@ -8,19 +8,19 @@ import org.asciidoctor.ast.DocumentHeader;
import org.asciidoctor.converter.JavaConverterRegistry;
import org.asciidoctor.extension.ExtensionGroup;
import org.asciidoctor.extension.JavaExtensionRegistry;
+import org.asciidoctor.extension.RubyExtensionRegistry;
import org.asciidoctor.jruby.AsciidoctorJRuby;
-import org.asciidoctor.jruby.ast.impl.NodeConverter;
-import org.asciidoctor.jruby.syntaxhighlighter.internal.SyntaxHighlighterRegistryExecutor;
-import org.asciidoctor.log.LogHandler;
-import org.asciidoctor.log.LogRecord;
import org.asciidoctor.jruby.DirectoryWalker;
-import org.asciidoctor.extension.RubyExtensionRegistry;
import org.asciidoctor.jruby.ast.impl.DocumentHeaderImpl;
+import org.asciidoctor.jruby.ast.impl.NodeConverter;
import org.asciidoctor.jruby.converter.internal.ConverterRegistryExecutor;
import org.asciidoctor.jruby.extension.internal.ExtensionRegistryExecutor;
import org.asciidoctor.jruby.log.internal.JULLogHandler;
import org.asciidoctor.jruby.log.internal.JavaLogger;
import org.asciidoctor.jruby.log.internal.LogHandlerRegistryExecutor;
+import org.asciidoctor.jruby.syntaxhighlighter.internal.SyntaxHighlighterRegistryExecutor;
+import org.asciidoctor.log.LogHandler;
+import org.asciidoctor.log.LogRecord;
import org.asciidoctor.syntaxhighlighter.SyntaxHighlighterRegistry;
import org.jruby.*;
import org.jruby.exceptions.RaiseException;
@@ -29,7 +29,6 @@ import org.jruby.runtime.builtin.IRubyObject;
import java.io.*;
import java.util.*;
-import java.util.logging.Level;
import java.util.logging.Logger;
public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler {
@@ -482,11 +481,7 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler {
@Override
public void log(LogRecord logRecord) {
for (LogHandler logHandler : logHandlers) {
- try {
logHandler.log(logRecord);
- } catch (Exception e) {
- LOGGER.log(Level.WARNING, "Unexpected exception while logging Asciidoctor log entry", e);
- }
}
}
}

MODIFY
asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciidoctorLogsToConsole.java
asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciidoctorLogsToConsole.java
@@ -29,11 +29,7 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import static org.asciidoctor.OptionsBuilder.options;
-import static org.hamcrest.Matchers.both;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@@ -296,6 +292,26 @@ public class WhenAsciidoctorLogsToConsole {
assertThat(renderContent, containsString("HELLO WORLD"));
}
+ @Test
+ public void should_fail_convert_when_logHandler_throws_an_exception() {
+ // given
+ final String errorMessage = "Conversion aborted by LogHandler";
+ asciidoctor.registerLogHandler(logRecord -> {
+ throw new RuntimeException(errorMessage);
+ });
+ // when
+ try {
+ asciidoctor.convert(
+ "= Test\n\n== Something different\n\n[big]\nHello World",
+ options().option("sourcemap", "true").asMap());
+ } catch (Throwable t) {
+ // then
+ assertThat(t.getMessage(), containsString("Failed to load AsciiDoc document"));
+ final Throwable cause = t.getCause();
+ assertThat(cause.getClass(), equalTo(RuntimeException.class));
+ assertThat(cause.getMessage(), is(errorMessage));
+ }
+ }
}

allow LogHandlers to break conversion throwing an exception