Skip to content

Commit aee2077

Browse files
committed
fixup: prepend error listener + test
1 parent f71dcd9 commit aee2077

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/_stream_writable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ function onFinished(stream, state, cb) {
727727
stream.removeListener('error', onerror);
728728
cb();
729729
}
730-
stream.on('finish', onfinish);
731-
stream.on('error', onerror);
730+
stream.prependListener('finish', onfinish);
731+
stream.prependListener('error', onerror);
732732
}
733733

734734
Object.defineProperty(Writable.prototype, 'destroyed', {

test/parallel/test-stream-writable-destroy.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,19 @@ const assert = require('assert');
328328
}));
329329
write.end();
330330
}
331+
332+
{
333+
// Call end(cb) after error & destroy and don't trigger
334+
// unhandled exception.
335+
336+
const write = new Writable({
337+
write(chunk, enc, cb) { process.nextTick(cb); }
338+
});
339+
write.once('error', common.mustCall((err) => {
340+
assert.strictEqual(err.message, 'asd');
341+
}));
342+
write.end('asd', common.mustCall((err) => {
343+
assert.strictEqual(err.message, 'asd');
344+
}));
345+
write.destroy(new Error('asd'));
346+
}

0 commit comments

Comments
 (0)