Skip to content

Commit

Permalink
fixup: prepend error listener + test
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Oct 11, 2019
1 parent f71dcd9 commit aee2077
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/_stream_writable.js
Expand Up @@ -727,8 +727,8 @@ function onFinished(stream, state, cb) {
stream.removeListener('error', onerror);
cb();
}
stream.on('finish', onfinish);
stream.on('error', onerror);
stream.prependListener('finish', onfinish);
stream.prependListener('error', onerror);
}

Object.defineProperty(Writable.prototype, 'destroyed', {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-stream-writable-destroy.js
Expand Up @@ -328,3 +328,19 @@ const assert = require('assert');
}));
write.end();
}

{
// Call end(cb) after error & destroy and don't trigger
// unhandled exception.

const write = new Writable({
write(chunk, enc, cb) { process.nextTick(cb); }
});
write.once('error', common.mustCall((err) => {
assert.strictEqual(err.message, 'asd');
}));
write.end('asd', common.mustCall((err) => {
assert.strictEqual(err.message, 'asd');
}));
write.destroy(new Error('asd'));
}

0 comments on commit aee2077

Please sign in to comment.