markushedvall / node-plantuml

A Node.js module and CLI for running PlantUML
MIT License
189 stars 53 forks source link

Crash Error Without Useful Error Message #7

Open jeremykentbgross opened 8 years ago

jeremykentbgross commented 8 years ago

Really basic code usages gives unhelpful error. The target file is generated, but it contains 0 bytes.

var plantuml = require('node-plantuml'); plantuml.generate( //Example input copied from: http://plantuml.com/PlantUML_Language_Reference_Guide.pdf "@startuml\n"

events.js:85 throw er; // Unhandled 'error' event ^ Error: spawn java ENOENT at exports._errnoException (util.js:746:11) at Process.ChildProcess._handle.onexit (child_process.js:1046:32) at child_process.js:1137:20 at process._tickCallback (node.js:355:11) at Function.Module.runMain (module.js:503:11) at startup (node.js:129:16) at node.js:814:3

package.json contains: "node-plantuml" : "0.4.4"

I am on Ubuntu 14.04 if that helps.

It is also worth noting that the existing documentation on the github page as well as the npm package is wrong, because the code crashes right away if no "options" parameter is provided. I was only able to deduce what seemed like it should be working code from exploring the source code in the repository.

jeremykentbgross commented 8 years ago

It seems this was because I didn't have the default-jre installed. I also needed graphviz.

Solved with: sudo apt-get install default-jre sudo apt-get install graphviz

Still I wonder if there is a way the lib could more helpfully return info on this for others. In any case, all is well that ends well.

aduh95 commented 4 years ago

Antoher problem I am facing in my app, is that I cannot catch the error message to display a fallback to my users:

const plantuml = require("node-plantuml");

console.log("The app starts");
setImmediate(() => console.log("Some async task here"));

try {
  plantuml.generate("./test.puml");
} catch {
  console.warn("Plantuml decoding is not available");
}

console.log("The app continues");

The async task is never hit:

>node plantuml-test.js
The app starts
The app continues
events.js:180
      throw er; // Unhandled 'error' event
      ^

Error: spawn java ENOENT
...

I would expect instead to get the following output:

> node plantuml-test.js
The app starts
Plantuml decoding is not available
The app continues
Some async task here
markushedvall commented 4 years ago

Thanks for the input. I misunderstood the error output. I thought spawn threw an error but it's actually an error event.

I've been working on improving error & event handling recently and hope to have a fix for this soon.

const gen = plantuml.generate("./test.puml");
gen.on('error', (err) => console.log(...))

That wan't help you to check if plantuml is available to use in advance though. Maybe it would be a good idea to be able to check java availability, similar how testdot can be used to check grahpviz availability.

simonvpe commented 4 years ago

+1 I spent a fair bit of time figuring out that my Docker container didn't have Java, and that it was a requirement.

I would suggest mentioning it as a dependency in the documentation in addition to the fix that you are working on.