plantuml / plantuml

Generate diagrams from textual description
https://plantuml.com
Other
9.73k stars 881 forks source link

Stack trace on console, but error code 0 #566

Open kriegaex opened 2 years ago

kriegaex commented 2 years ago

I found a diagram containing this line in another project:

!pragma graphviz_dot jdot

When running PlantUML 1.2020.19 together with a Graphviz 2.47.1 Windows installation (final release, no extras or betas installed), the following happens (Windows Git Bash):

$ java -jar plantuml-1.2020.19.jar -version
PlantUML version 1.2020.19 (Mon Oct 12 22:10:01 ICT 2020)
(GPL source distribution)
Java Runtime: Java(TM) SE Runtime Environment
JVM: Java HotSpot(TM) 64-Bit Server VM
Default Encoding: Cp1252
Language: de
Country: DE

PLANTUML_LIMIT_SIZE: 4096

Dot version: dot - graphviz version 2.47.1 (20210417.1919)
Installation seems OK. File generation OK

$ java -jar plantuml-1.2020.19.jar diagram.puml

java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at smetana.core.CFunctionImpl.exe(CFunctionImpl.java:79)
        at gen.lib.gvc.gvlayout__c.gvLayoutJobs(gvlayout__c.java:245)
        at net.sourceforge.plantuml.jdot.CucaDiagramFileMakerJDot.createFileLocked(CucaDiagramFileMakerJDot.java:434)
        at net.sourceforge.plantuml.jdot.CucaDiagramFileMakerJDot.createFile(CucaDiagramFileMakerJDot.java:388)
        at net.sourceforge.plantuml.cucadiagram.CucaDiagram.exportDiagramInternal(CucaDiagram.java:654)
        at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:173)
        at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:140)
        at net.sourceforge.plantuml.PSystemUtils.exportDiagramsCuca(PSystemUtils.java:233)
        at net.sourceforge.plantuml.PSystemUtils.exportDiagrams(PSystemUtils.java:89)
        at net.sourceforge.plantuml.SourceFileReaderAbstract.getGeneratedImages(SourceFileReaderAbstract.java:160)
        at net.sourceforge.plantuml.Run.manageFileInternal(Run.java:538)
        at net.sourceforge.plantuml.Run.processArgs(Run.java:422)
        at net.sourceforge.plantuml.Run.manageAllFiles(Run.java:389)
        at net.sourceforge.plantuml.Run.main(Run.java:198)
Caused by: java.lang.ClassFormatError: Illegal local variable table length 119 in method 'void gen.lib.dotgen.cluster__c.map_path(h.ST_Agnode_s, h.ST_Agnode_s, h.ST_Agedge_s, h.ST_Agedge_s, int)'
        at gen.lib.dotgen.class1__c.class1_(class1__c.java:768)
        at gen.lib.dotgen.rank__c.dot1_rank(rank__c.java:1263)
        at gen.lib.dotgen.rank__c.collapse_cluster(rank__c.java:1026)
        at gen.lib.dotgen.rank__c.collapse_sets(rank__c.java:1049)
        at gen.lib.dotgen.rank__c.dot1_rank(rank__c.java:1261)
        at gen.lib.dotgen.rank__c.dot_rank(rank__c.java:1297)
        at gen.lib.dotgen.dotinit__c.dotLayout(dotinit__c.java:1063)
        at gen.lib.dotgen.dotinit__c.doDot(dotinit__c.java:1186)
        at gen.lib.dotgen.dotinit__c.dot_layout(dotinit__c.java:1236)
        ... 18 more
java.lang.UnsupportedOperationException: gen.lib.dotgen.dotinit__c::dot_layout
        at smetana.core.CFunctionImpl.exe(CFunctionImpl.java:82)
        at gen.lib.gvc.gvlayout__c.gvLayoutJobs(gvlayout__c.java:245)
        at net.sourceforge.plantuml.jdot.CucaDiagramFileMakerJDot.createFileLocked(CucaDiagramFileMakerJDot.java:434)
        at net.sourceforge.plantuml.jdot.CucaDiagramFileMakerJDot.createFile(CucaDiagramFileMakerJDot.java:388)
        at net.sourceforge.plantuml.cucadiagram.CucaDiagram.exportDiagramInternal(CucaDiagram.java:654)
        at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:173)
        at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:140)
        at net.sourceforge.plantuml.PSystemUtils.exportDiagramsCuca(PSystemUtils.java:233)
        at net.sourceforge.plantuml.PSystemUtils.exportDiagrams(PSystemUtils.java:89)
        at net.sourceforge.plantuml.SourceFileReaderAbstract.getGeneratedImages(SourceFileReaderAbstract.java:160)
        at net.sourceforge.plantuml.Run.manageFileInternal(Run.java:538)
        at net.sourceforge.plantuml.Run.processArgs(Run.java:422)
        at net.sourceforge.plantuml.Run.manageAllFiles(Run.java:389)
        at net.sourceforge.plantuml.Run.main(Run.java:198)

$ echo $?
0

I understand if the Jdot or Smetana or whatever-you-call-it feature is unavailable or not working without special configuration. But if such a clear error occurs and a long stack trace is written to the console, how can the return code be 0? Also, when processing the same diagram with PlantUML Maven plugin, the build is reported to be successful and no error or stack trace printed to the console either, probably because the exit code is 0.

Please fix this problem in particular ASAP. Also, more generally, provide a means to get access to detailed error information when calling SourceFileReader.getGeneratedImages (method actually is defined in SourceFileReaderAbstract). I see no obvious way to find out via API what happened. Some error information is kept in internal variables, but the seem to be inaccessible via public API. This makes it next to impossible for a client like the Maven plugin to determine if errors occurred at all and, if so, which ones.

This might be related to #258.

kriegaex commented 2 years ago

By the way, if on non-Windows operating systems like Linux Graphviz is not installed or cannot be found on the path, the exact same thing happens:

$ java -jar plantuml-1.2020.19.jar src/site/uml/multimodule_ajc.puml
java.io.IOException: Cannot run program "/opt/local/bin/dot": error=2, No such file or directory
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
        at java.base/java.lang.Runtime.exec(Runtime.java:590)
        at net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner$MainThread.startThreads(ProcessRunner.java:163)
        at net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner$MainThread.runJob(ProcessRunner.java:123)
        at net.sourceforge.plantuml.api.TimeoutExecutor$MyThread.run(TimeoutExecutor.java:79)
Caused by: java.io.IOException: error=2, No such file or directory
        at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
        at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:319)
        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:250)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
        ... 5 more
java.io.IOException: Cannot run program "/opt/local/bin/dot": error=2, No such file or directory
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
        at java.base/java.lang.Runtime.exec(Runtime.java:590)
        at net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner$MainThread.startThreads(ProcessRunner.java:163)
        at net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner$MainThread.runJob(ProcessRunner.java:123)
        at net.sourceforge.plantuml.api.TimeoutExecutor$MyThread.run(TimeoutExecutor.java:79)
Caused by: java.io.IOException: error=2, No such file or directory
        at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
        at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:319)
        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:250)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
        ... 5 more

$ echo $?
0

Only God knows why the same stack trace is printed twice in this case.

VladimirAlexiev commented 2 years ago

A agree it should return an error code when throwing an exception.

Couple of general remarks:

kriegaex commented 2 years ago

@VladimirAlexiev, are you commenting as a co-user or are you a contributor to this project? I am just asking because I want to understand if I finally got the attention of someone who is able to fix this or not.

My question is not so much about Smetana as such, but rather about error handling in general. I actually was not using PlantUML directly but from a Maven plugin which depended on the 1.2020.19 version. Then I debugged and ran PlantUML directly in order to track down the problem.

Anyway, the idea to try and run this on a more recent PlantUML version was an interesting one, so I tried on 1.2021.7 and 1.2021.8. Both versions actually show another error message, much shorter and without stack trace:

Error line 2 in file: src\site\uml\multimodule_ajc.puml
Some diagram description contains errors

They also return error code 200, not 0. So it looks like someone has improved something in this area already. I also found out that instead of !pragma graphviz_dot jdot now the pragma should be !pragma layout smetana. The resulting PNG looks a little similar with regard to layout spacing (more dense), but is recognisable the same diagram.


May I ask a related question: When starting with PlantUML, I had to install Graphviz locally on my machine. I tried to check that with Sematana actually Graphviz is no longer needed and renamed the program directory. It worked. But to my surprise, it also continued working when removing the Sematana pragma. Also, the version umber displayed by java -jar plantuml-1.2020.19.jar -version is different from the local installation, i.e. PlantUML somehow seems to find Graphviz somewhere else. How does that work? I also remember, the Maven plugin did not work on GitHub CI, until I added a Graphviz installation step to my GitHub workflow. Why is this working now, even without activating Smetana? I am confused.

VladimirAlexiev commented 2 years ago

I'm just a user.

PlantUML is very smart when trying to get hold of dot, see https://plantuml.com/graphviz-dot. Also check $PATH, $GRAPHVIZ_DOT, which dot.

In your case I think it's installing the bundled temp version of dot

kriegaex commented 2 years ago

Your message intersected with my own research. I found out that actually since 1.2020.25 it works on my Windows box. Graphviz definitely is not found on the path, because I renamed the folder, like I said. The link you provided explains it:

Installation under Windows

If you use a recent version (that is at least version 1.2020.21), you don't need to manually install GraphViz anymore !

A minimalistic graphviz dot.exe is packed into PlantUML and will be automagically unzipped in some temporary folder if needed (that is, if no installed GraphViz is available).

This is really the prefered option under Windows.

So the caveat is: only on Windows. For my CI builds on Linux and MacOS, I still need a local Graphviz installation. I only tried on Windows today, hence the result. But versions 1.2020.21-24 throw errors on my box, it seems there was a bug concerning instantiating BrotliInputStream which is gone since .25. Now everything is clear, thanks for your help. Fun fact: 1.2020.25 fixed this problem, but of all versions exactly that one is omitted in the release notes overview.


Update: !pragma layout smetana works since 1.2021.5 (before there was a fall-back to Graphviz), but this fact is also not mentioned in the release notes. It is really detective work to find out anything about this project...

VladimirAlexiev commented 2 years ago

Please contribute to the documentation! On any page section there are buttons to edit it in several text formats.

Your investigative effort shouldn't be lost.

And close this issue.

kriegaex commented 2 years ago

Like this? I am showing the edit page, because even though I clicked "save", the new content is not visible on https://plantuml.com/graphviz-dot. Maybe someone needs to review and publish them first, I have no idea.

image

VladimirAlexiev commented 2 years ago

Yes, your edits will be approved by the author.

But there is https://plantuml.com/smetana02: maybe some of your text belongs there, and surely interlink the two pages.

Thanks for contributing! If you want to document more, I'll send you a list.

kriegaex commented 2 years ago

I added a link:

image

Thanks for contributing! If you want to document more, I'll send you a list.

No, thank you. In the project I am contributing to, there is a single, small UML diagram as part of the documentation. I already fixed the PlantUML Maven plugin, so it runs fine on JDK 8-16 on Windows, MacOS and Linux, fixed the tests in that plugin and reported an issue here. I fell way deeper into the rabbit hole than I wanted to already.