Skip to content

Commit

Permalink
handle output from stderr. closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindfjeldstad committed May 14, 2014
1 parent 7632f68 commit 6c7979c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Expand Up @@ -222,11 +222,24 @@ ImageMagick.prototype = {
var stdout = proc.stdout;
stdout.on('error', this.onerror);
stdout.pipe(this.out);

var stderr = proc.stderr;
stderr.on('data', this.onerror);
stderr.on('error', this.onerror);

this.emit('spawn', proc);
},

/**
* Re-emit errors
*
* @param {Error|Buffer} err
* @api private
*/

onerror: function (err) {
if (!isError(err)) err = new Error(err);
if (!this.listeners('error')) throw err;
this.emit('error', err);
}
};
10 changes: 10 additions & 0 deletions test/index.js
Expand Up @@ -28,6 +28,16 @@ describe('im()', function () {
});
});

it('should emit errors from stderr', function (done) {
var img = im();
img.write('invalid data');
img.end();
img.on('error', function (err) {
assert(/^convert\:/.test(err.message));
done();
});
});

describe('.from()', function () {
it('should read from the given path', function (done) {
var img = im().from(__dirname + '/test.jpg');
Expand Down

0 comments on commit 6c7979c

Please sign in to comment.