asciidoctor / asciidoctor-diagram

:left_right_arrow: Asciidoctor diagram extension, with support for AsciiToSVG, BlockDiag (BlockDiag, SeqDiag, ActDiag, NwDiag), Ditaa, Erd, GraphViz, Mermaid, Msc, PlantUML, Shaape, SvgBob, Syntrax, UMLet, Vega, Vega-Lite and WaveDrom.
http://asciidoctor.org
MIT License
435 stars 106 forks source link

Rendering of syntax errors in PlantUML diagrams terminate rendering #355

Closed ahus1 closed 3 years ago

ahus1 commented 3 years ago

When adding the following snippet to an AsciiDoc file,

[plantuml]
----
@startuml
xxx
@enduml
----

the rendering terminates, and no HTML output is produced. Instead there is an exception for with an error message:

$ asciidoctor -r asciidoctor-diagram test.adoc
asciidoctor: ERROR: test.adoc: line 2: Failed to generate image: PlantUML preprocessing failed: [From <input> (line 2) ]

@startuml
xxx
^^^^^
 Syntax Error?

asciidoctor: FAILED: C:/workspace/asciidoc/sample/test.adoc: Failed to load AsciiDoc document - PlantUML preprocessing failed: [From <input> (line 2) ]

@startuml
xxx
^^^^^
 Syntax Error?
 (RuntimeError)
  Use --trace for backtrace

This behavior is different from before, as before change 06baa8ed2c841c8a6e32ed785302f98febce676e and errors in PlantUML processing would be handled by the begin/end/rescue block in convert.rb and would render a text block with a message instead of the diagram on all errors as default.

Unfortunately errors that occur in wrap_source are before the "begin", therefore the exception will bubble up and no error text will be put into the document.

When users have a preview that renders automatically when typing text (like in the IntelliJ plugin), it would be nice if these kind of errors would display as text blocks, so that an error in the PlantUML wouldn't destroy the complete preview.

Therefore I would expect preprocessor errors to be handled like any other error.

My (maybe naive) suggestion: Move wrap_source in the begin, so that is participates in the error handling. Its hard for me to tell if this would break other people's expectations.

pepijnve commented 3 years ago

@ahus1 your suggestion is not naive at all; this is indeed a bit of a regression. Moving the wrap_source call inside the begin/rescue will fix this.