Skip to content

Commit

Permalink
Merge pull request #26 from BridgeAR/master
Browse files Browse the repository at this point in the history
Fix missing error handling
  • Loading branch information
glejeune authored Mar 18, 2018
2 parents d202f98 + a6ea928 commit bb43204
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/graphviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ exports.graph = function(id) {
* @constructor
* @param {String} id The graphID
* @return {Graph}
* @api public
* @api public
*/
exports.digraph = function(id) {
var graph = new Graph(null, id);
graph.type = 'digraph';
return graph;
return graph;
};

function _parse(file, callback, errback) {
Expand All @@ -53,8 +53,8 @@ function _parse(file, callback, errback) {
graphviz.stdin.end();
graphviz.on('exit', function(code) {
if(code !== 0 || __graph_eval === undefined) {
if(errback) {
errback(code, out, err);
if(errback) {
errback(code, out, err);
}
} else {
callback(__graph_eval);
Expand All @@ -67,16 +67,26 @@ function _parse(file, callback, errback) {
* @param {String} file_or_script The DOT script or file
* @param {Function} callback
* @param {Function} errback
* @api public
* @api public
*/
exports.parse = function(file_or_script, callback, errback) {
if(fsExt.exist(file_or_script)) {
_parse(file_or_script, callback, errback);
} else {
temp.open('node-graphviz', function(err, info) {
fs.write(info.fd, file_or_script);
fs.close(info.fd, function(err) {
_parse(info.path, callback, errback);
if(err) {
return errback(err);
}
fs.write(info.fd, file_or_script, function(err) {
if(err) {
return errback(err);
}
fs.close(info.fd, function(err) {
if(err) {
return errback(err);
}
_parse(info.path, callback, errback);
});
});
});
}
Expand Down

0 comments on commit bb43204

Please sign in to comment.