Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: prepend error listener + test
  • Loading branch information
ronag committed Oct 11, 2019
commit aee2077b961c84e9f01653bbe640b0b277c0508a
4 changes: 2 additions & 2 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
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);
}
Comment thread
ronag marked this conversation as resolved.
Outdated

Object.defineProperty(Writable.prototype, 'destroyed', {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-stream-writable-destroy.js
Original file line number Diff line number Diff line change
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'));
}