Skip to content

Commit

Permalink
Callback not receiving errors (#72)
Browse files Browse the repository at this point in the history
* Changed the error variable on the child close event so it returns the error to the callback. I left the original logic of checking for a code, if error isn’t set.

* Removed unncessary ternary statement.

* Fixed the unit test, since error is only returned if an error is passed to the callback.

* Fixed lint error.
  • Loading branch information
chadrickman authored and deiga committed Apr 4, 2018
1 parent 8f55ced commit 2ec885e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/growl.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,13 @@ function growl(msg, opts, callback) {
stderr += data;
});

child.on('close', (code) => {
error = error || code === 0 ? null : code;
child.on('close', () => {
if (typeof fn === 'function') {
fn(error, stdout, stderr);
}
});
}


/**
* Expose `growl`.
*/
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ growl('Show pdf filesystem icon', { image: 'article.pdf' }, function(){
})
growl('Show pdf filesystem icon', { title: 'Use show()', image: 'article.pdf' })
growl('here \' are \n some \\ characters that " need escaping', {}, function(error, stdout, stderr) {
if (error !== null) throw new Error('escaping failed:\n' + stdout + stderr);
if (error) throw new Error('escaping failed:\n' + stdout + stderr);
})
growl('Allow custom notifiers', { exec: 'echo XXX %s' }, function(error, stdout, stderr) {
console.log(stdout);
Expand Down

0 comments on commit 2ec885e

Please sign in to comment.