-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Conversation
ping @lpinca |
The first stream error is the only one that gets emitted as 'error' or forwarded in callbacks. Also it cannot be override by _destroy. Refs: nodejs#30979
4af24a5
to
2c96024
Compare
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
destroy(err, cb)
is now able to override the no error state from destroy()
above.
@addaleax: This fails in |
17b34a4
to
339aa07
Compare
|
||
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 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?
@@ -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')); |
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?
@nodejs/streams |
s/overriden/overridden/ in commit message |
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.
I'm -1 for this change. The purpose of the err
parameter in _destroy()
is to be able to change/handle the errors.
I'm not sure what is the context of this change and I don't get how #30979 lead to this.
But that doesn't really work in practice? e.g. const { Readable } = require('stream');
stream = new Readable({
read() {},
destroy (err, cb) {
setTimeout(() => {
cb(new Error('other error'));
}, 100);
}
})
stream.destroy(new Error('error 1'));
stream.destroy(new Error('error 2'));
stream.on('error', (err) => {
console.log(err.message); // prints 'error 2', confusion
}); |
This comment has been minimized.
This comment has been minimized.
I do not have a better suggestion. The only other way I can think of to make this behave in a consistent manner is to ignore any |
I actually kind of like this option. Doing it like this would make things a lot easier both in terms of implementation and user complexity. It kind of goes back to the discussion in #29197 where we originally discussed not allowing any errors after |
-1, in this case I want the error to surface if the |
That would be something like?
@lpinca: One problem with this is:
|
Yes which brings us back to #30979. We are running in circles. I like the simplicity and predictability of the solution proposed here. |
Yes, you are right. As far as I see the current situation is:
|
I think I was most comfortable with the approach in #29197... Or at least it makes sense to me that |
This comment has been minimized.
This comment has been minimized.
@mcollina: as we seem a bit stuck with this would it make sense to raise this to TSC? It's a bit re-occuring and touches a few different areas. If required I could write a short summary of the discussed issues and solutions based on #30982, #29197, #30979, #30970, #30906. The question is which direction to go amongst #30982 (comment) (or something else). |
I think that would be helpful, I’m happy to review that document before it’s shared with everybody. |
If this is not acceptable my vote is for keeping things as is. In my opinion #30979 is an edge case that is probably not worth fixing. I think that custom |
Closing this for now pending #31060 |
The first stream error is the only one that gets emitted as
'error'
or forwarded through callbacks. Also it cannot be overriden or swallowed by_destroy
. This is in order to easier reason what will happen in regards to streams and errors. Currently it's quite difficult to know what to expect in different cases.See #30979 for further discussion.
destroy(err, cb)
, i.e.destroy
with callback is now also able to actually override the error (see https://github.com/nodejs/node/pull/30982/files#r357996368). I don't believe this affects anything in practice.semver-major
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes