From 774cb08953f649aa8777afa974ccd4263688635b Mon Sep 17 00:00:00 2001 From: Lucia Espona Pernas Date: Mon, 10 May 2021 16:09:16 +0200 Subject: [PATCH] Update graph.js Handle the error when the dot command fails to run (ex. 'dot' is not installed). Write to input only when the command is running. --- lib/deps/graph.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/deps/graph.js b/lib/deps/graph.js index 3b9c5b5..6ae35c3 100644 --- a/lib/deps/graph.js +++ b/lib/deps/graph.js @@ -410,6 +410,9 @@ Graph.prototype.render = function(type_or_options, name_or_callback, errback) { } } else { graphviz = spawn(cmdPath, parameters); + graphviz.on('error', function(err) { + errback(-1, "", err) + }); graphviz.stdout.on('data', outcallback); graphviz.stderr.on('data', function(data) { err += data; @@ -424,8 +427,10 @@ Graph.prototype.render = function(type_or_options, name_or_callback, errback) { else if (errback) errback(code, out, err) } }); - graphviz.stdin.write(self.to_dot()); - graphviz.stdin.end(); + if (graphviz.pid) { + graphviz.stdin.write(self.to_dot()); + graphviz.stdin.end(); + } } }); };