question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

better stream error handling

See original GitHub issue

Some 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:closed
  • Created 10 years ago
  • Comments:36 (34 by maintainers)

github_iconTop GitHub Comments

2reactions
juliangrubercommented, May 15, 2015

@rtm

var archiver = new Archiver('zip');
this.body = archiver;
// ...
archiver.finalize();
0reactions
rtmcommented, May 15, 2015

@juliangruber Thanks, how obvious.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found