Description
- v4.4.1:
- Darwin Bens-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0: Wed Mar 18 16:20:14 PDT 2015; root:xnu-2422.115.14~1/RELEASE_X86_64 x86_64:
- Subsystem:
While dealing with a weird uncaughtException, emitted by a stream. It inspires me this idea, maybe .pipe()
can do one more thing to bind an error listener on the src
and emit ( forward ) the error to dest
automatically.
The benefit is: We can easily handle the error on the destination, and no worry that error might be emitted on somewhere we forgot or have no access to it.
In my case, for testing purpose, I emit error on the query object created by node-mysql, and keep to get uncaughtException
, I checked all the EventEmitters on the scope, and don't know why it happened. Till the end, I understand, node-mysql forward
the error from the query object to the stream, and my database api(my another module not written in the current module) pipe that stream to a Transform stream and return that transform stream to me. I forgot the stream is not the stream originally created by node-mysql, and to avoid potential uncaughtException, I decide to add error listener to the original stream.
It makes the codes ugly, previously. it is
return query.stream().pipe(NormalizeData());
and now, it becomes
var s = query.stream();
var n = NormalizeData():
s.on('error', err=> n.emit('error', err));
return s.pipe(n);
It's just an idea, please feel free to close it, if it is no sense :)