better stream error handling
See original GitHub issueSome ideas how to better handle streams, the biggest problem being error handling.
As in https://github.com/koajs/koa/issues/180#issuecomment-32126654
// what you have to do currently
// ugly as fuck
app.use(function*(){
var a = streamA().on('error', this.onerror);
var b = streamB().on('error', this.onerror);
this.body = a.pipe(b).pipe(streamC());
});
With multipipe.
// with `multipipe`
app.use(function*(){
this.body = pipe(streamA(), streamB(), streamC());
});
// for fs leaks, also accept functions as this.body
// and call them when no other handler is set
// leaky as fuck
app.use(function*(){
this.body = fs.createReadStream.bind(null, 'file.html');
});
Issue Analytics
- State:
- Created 10 years ago
- Comments:36 (34 by maintainers)
Top Results From Across the Web
Error handling with node.js streams - Stack Overflow
Transform streams are both readable and writeable, and thus are really good 'middle' streams. For this reason, they are sometimes referred to as ......
Read more >Pipeline API - the best way to handle stream errors that ...
Streams are considered a pillar of NodeJS but also one of the hardest concepts to grasp, especially when it comes to error handling....
Read more >How to handle stream errors? - Mario Kandut
To handle error events attach an event handler directly on the stream. Let's create a PassThrough stream and add event handlers. Create a...
Read more >How to handle exceptions properly within streams - Medium
The only advice I found by googling was to handle the exception within a method to make the code more readable. Really, is...
Read more >Error Handling in Streams - Documentation - Akka
Throwing an exception inside recover will be logged on ERROR level automatically. More details in recover. Scala: copy source Source(0 to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rtm
@juliangruber Thanks, how obvious.