[nodejs] Re: Should stream.pipe forward errors?

2012-11-28 Thread Marco Rogers
Yeah I wish there was a better story for this. It's easy to forward errors. It could become difficult to determine in what context the error was thrown. :Marco On Wednesday, November 28, 2012 9:10:51 AM UTC-8, Jeff Barczewski wrote: > > I was recently testing some stream piping like > > rstream

[nodejs] Re: Should stream.pipe forward errors?

2012-11-28 Thread Jeff Barczewski
Agreed. Especially if the error happens after the initial connection (which is probably when most would occur), then it won't be caught by any try/catch so it would have to rely on domains. If you have setup an error handler then it is just nice to deal with it there in one spot. -- Job Boa

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-28 Thread Mikeal Rogers
with domains, these will all get trapped in the same domain because they are all event emitters, if they throw. i tried forwarding errors through pipe chains but it ended up being problematic and i've since backed off. On Nov 28, 2012, at November 28, 20121:24 PM, Marco Rogers wrote: > Yeah

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-28 Thread Marco Rogers
What was problematic about it? Also I though event emitters had to be explicitly added to domains. On Wed, Nov 28, 2012 at 4:47 PM, Mikeal Rogers wrote: > with domains, these will all get trapped in the same domain because they > are all event emitters, if they throw. > > i tried forwarding erro

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-28 Thread Dan Milon
Technically you could explicitly add each stream to its own domain. danmilon. On 11/29/2012 02:47 AM, Mikeal Rogers wrote: > with domains, these will all get trapped in the same domain because > they are all event emitters, if they throw. > > i tried forwarding errors through pipe chains but it

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-28 Thread Dominic Tarr
Thinking about this, usually each stream produces errors in a special way, normal javascript errors, (like property of null, etc) throw instead of emitting, so there is no way to catch the error. domains fit this case. Usually, only streams that actually do IO emit errors, which is mostly the firs

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-28 Thread Martin Cooper
On Wed, Nov 28, 2012 at 2:05 PM, Jeff Barczewski wrote: > Agreed. Especially if the error happens after the initial connection > (which is probably when most would occur), then it won't be caught by any > try/catch so it would have to rely on domains. > > If you have setup an error handler then it

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-29 Thread Jeff Barczewski
@Dominic Yes, IO errors would be primary need, but also some pass-through streams that parse data could also emit errors (if the data wasn't as expected) which we would want to handle at the final error handler. So a concrete example using some simple pass-through streams: rstream

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-29 Thread Isaac Schlueter
The biggest problem with forwarding errors happens when you have duplex streams that forward to one another, and as Martin points out, streams that emit errors in different circumstances. For example, let's say that you added something like this in the pipe() function: src.on('error', functio

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-29 Thread Jeff Barczewski
@Martin That is a good point about if I have source error listener then I shouldn't need to forward the error. So maybe the logic could be the following for errors in a piped stream: 1. if any error listener on source, emit there only 2. else if any error listener on dest, forward the error to

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-29 Thread Jeff Barczewski
@Isaac You bring up a good point about the duplex streams, I can see how that could get hairy real quick. Your domains example is nice, so maybe that is the best way to handle error in a single place. For completeness and finishing the discussion around this, I can give one last idea. Since p

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-29 Thread Isaac Schlueter
Since pipe is used in a lot of very hot areas, and is a royal pain to make changes to, I'd suggest just leaving it as-is for now. That pipe option object is kind of a wart in my opinion, I'd rather not make it bigger. On Thu, Nov 29, 2012 at 9:50 AM, Jeff Barczewski wrote: > @Isaac You bring up

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-29 Thread Jeff Barczewski
Understood. Thanks for all the discussion. Using domains appears to be a good solution in addition to using individual listeners. -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-29 Thread Marco Rogers
This is all really good info and I'm not gonna argue. I still think it'd be nice if there was a nicer shorthand to tell one emitter to forward certain events to another emitter. So at least it's less of a pain to do it manually. I kinda don't think there is a good shorthand though. Even adding it t

Re: [nodejs] Re: Should stream.pipe forward errors?

2012-11-30 Thread Isaac Schlueter
Marco, Easily monkeypatched/userlanded: Stream.prototype.pipeErr = function(dest, opt) { var fw = dest.emit.bind(dest, 'error') this.on('error', fw) var self = this dest.on('unpipe', function (src) { if (src === self) dest.removeListener('error', fw) }) return this.pipe(dest

Re: [nodejs] Re: Should stream.pipe forward errors?

2014-02-07 Thread George Snelling
Tickling this thread since I just wasted a few hours scratching my head expecting code that looked a lot like what Jeff wrote below to work. It doesn't. Kind Node Keepers: the streams docs could use some attention and examples on error handling in a multi-step stream pipeline. Thanks for you