-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream: first error wins and cannot be overriden #30982
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,27 +86,29 @@ const assert = require('assert'); | |
{ | ||
const r = new stream.Readable({ | ||
read() { | ||
r2.emit('error', new Error('fail')); | ||
r2.destroy(new Error('fail')); | ||
} | ||
}); | ||
const r2 = new stream.Readable({ | ||
autoDestroy: true, | ||
destroy: common.mustCall((err, cb) => cb()) | ||
}); | ||
r2.on('error', common.mustCall()); | ||
|
||
r.pipe(r2); | ||
} | ||
|
||
{ | ||
const r = new stream.Readable({ | ||
read() { | ||
w.emit('error', new Error('fail')); | ||
w.destroy(new Error('fail')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note this change. Calling |
||
} | ||
}); | ||
const w = new stream.Writable({ | ||
autoDestroy: true, | ||
destroy: common.mustCall((err, cb) => cb()) | ||
}); | ||
w.on('error', common.mustCall()); | ||
|
||
r.pipe(w); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,8 +83,33 @@ const assert = require('assert'); | |
write.on('finish', common.mustNotCall('no finish event')); | ||
write.on('close', common.mustCall()); | ||
|
||
// Error is swallowed by the custom _destroy | ||
write.on('error', common.mustNotCall('no error event')); | ||
// Error is NOT swallowed by the custom _destroy | ||
write.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err, expected); | ||
})); | ||
|
||
write.destroy(expected); | ||
assert.strictEqual(write.destroyed, true); | ||
} | ||
|
||
{ | ||
const write = new Writable({ | ||
write(chunk, enc, cb) { cb(); }, | ||
destroy: common.mustCall(function(err, cb) { | ||
assert.strictEqual(err, expected); | ||
cb(new Error('not this error')); | ||
}) | ||
}); | ||
|
||
const expected = new Error('kaboom'); | ||
|
||
write.on('finish', common.mustNotCall('no finish event')); | ||
write.on('close', common.mustCall()); | ||
|
||
// Error is NOT overriden by the custom _destroy | ||
write.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err, expected); | ||
})); | ||
|
||
write.destroy(expected); | ||
assert.strictEqual(write.destroyed, true); | ||
|
@@ -167,9 +192,10 @@ const assert = require('assert'); | |
assert.strictEqual(write._writableState.errorEmitted, true); | ||
})); | ||
|
||
write.destroy(new Error('kaboom 1')); | ||
const expected = new Error('kaboom 1'); | ||
write.destroy(expected); | ||
write.destroy(new Error('kaboom 2')); | ||
assert.strictEqual(write._writableState.errored, true); | ||
assert.strictEqual(write._writableState.errored, expected); | ||
assert.strictEqual(write._writableState.errorEmitted, false); | ||
assert.strictEqual(write.destroyed, true); | ||
ticked = true; | ||
|
@@ -198,14 +224,15 @@ const assert = require('assert'); | |
|
||
writable.destroy(); | ||
assert.strictEqual(writable.destroyed, true); | ||
assert.strictEqual(writable._writableState.errored, false); | ||
assert.strictEqual(writable._writableState.errored, null); | ||
assert.strictEqual(writable._writableState.errorEmitted, false); | ||
|
||
// Test case where `writable.destroy()` is called again with an error before | ||
// the `_destroy()` callback is called. | ||
writable.destroy(new Error('kaboom 2')); | ||
const expected = new Error('kaboom 2'); | ||
writable.destroy(expected); | ||
assert.strictEqual(writable._writableState.errorEmitted, false); | ||
assert.strictEqual(writable._writableState.errored, true); | ||
assert.strictEqual(writable._writableState.errored, expected); | ||
|
||
ticked = true; | ||
} | ||
|
@@ -249,6 +276,9 @@ const assert = require('assert'); | |
write.destroy(expected, common.mustCall(function(err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
assert.strictEqual(err, expected); | ||
})); | ||
write.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err, expected); | ||
})); | ||
} | ||
|
||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note this change. Calling
emit('error'
is not something that should be done. But do we need to support it?