-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Streams: forward errors on pipe #1521
Conversation
@@ -447,6 +447,7 @@ Readable.prototype._read = function(n) { | |||
Readable.prototype.pipe = function(dest, pipeOpts) { |
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.
We should probably add this option to Stream.prototype.pipe
as well.
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.
Probably I forgot about that one
Adds an option for stream piping to enable errors to be pass along the pipe chain. Defaults it to false for it to be opt-in. This is an option to make our streams more in line with whatwg streams.
c793225
to
b537275
Compare
@@ -447,6 +447,7 @@ Readable.prototype._read = function(n) { | |||
Readable.prototype.pipe = function(dest, pipeOpts) { | |||
var src = this; | |||
var state = this._readableState; | |||
pipeOpts = pipeOpts || {}; |
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.
should we care that in a typical use-case this would create an arbitrary object?
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.
we also avoid an unnecessary conversion of undefined to a Boolean, I doubt it makes much difference
Can this be easily detected if it's set on a stream? Can I Also be aware that this will screw up a lot of user code that assumes that errors aren't forwarded, for example in bl which is in heavy use. And another thing:
My reading of the code says that this isn't quite accurate - errors aren't thrown if they are handled and my assumption when reading this description is that they are only forwarded if they were going to throw, i.e. if there was no other error handler. Perhaps tighten that description up a bit more. Overall I'm weary of this, I'd love for this to have been the default behaviour of streams from the beginning but we've built a whole ecosystem around the assumption that streams don't forward errors and you need to handle them all the way down; as crappy as that is. |
No. This is an option set on the Another concern: streams that don't support this option in |
indeed this is why it's opt in
will do
we could put an attribute on the new stream to say it supports the option |
it seems a little confusing. Essentially as a feature this would be advantage to have, and brings parity to WHATWG. Is the fact that it could lead mislead an user a game changer at this stage? I assume a lot of changes could also warrant these kinds of developer confusion. It would be important for changes like this to be well advertised. I can't think how this could otherwise be implemented without introducing this extra complexity 😕💭 |
We could give it a different method name like the equivalent whatwg stream On Wed, Apr 29, 2015, 4:08 PM Sam Newman [email protected] wrote:
|
@ForbesLindesay's prior art calls it syphon; seems reasonable. |
I like it, syphon as alias for pipe that adds the forward error thingy |
This is a nice feature! It makes work with streams more consistent with promises: getStream()
.pipe()
.pipe()
.pipe()
.on('error', onError) and the same thing with promises getPromise()
.then()
.then()
.then()
.catch(onError) It's nice to have one error handler at the end of chain instead of catching error after every operation |
@calvinmetcalf @chrisdickinson @trevnorris @rvagg ... what's the status on this one? |
I'm torn on this one, I wish it was the default but the ship has sailed. A possible compromise might be for the behaviour to be that it'll forward errors if there are no existing error listeners on the current stream, although that creates weird state and would likely go against most users' expectations. |
@rvagg I like that I'll update the patch to do just that |
ok so thinking through how only forward if there are no listeners, that is going to be tricky if it's part of a pipe because currently the stream that is piping to the stream has a listener and ends up throwing the error if nobody else is |
Why not just make a new function that does that automatically, with the intent of eventually deprecating the current It's fine to fear breaking things, but I think we might fear changing things a bit too much at times. With time, we can steer the community toward newer and better ways. |
@calvinmetcalf, do you mind stating in a sentence or two the resolution of this? |
pull for nodejs/readable-stream#129 cc @iojs/streams , still need to add documentation, tests, and clean up the commits