mafintosh / mafintosh/pump

Async errors not caught in Node < 10

Open
#51 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
917
Forks
64
PR merge metrics
No merged PRs in 30d

Description

I'm seeing different behaviour in Node 8 and 9 vs 10, 11 and 12.

The [Node 8 docs](https://nodejs.org/docs/latest-v8.x/api/stream.html#stream_readable_destroy_error) suggest an error is emitted when calling `Readable.prototype.destroy`, however `pump` doesn't propagate the error to the `callback`. e.g.

```js
const { Readable, Writable } = require('stream');
const pump = require('pump');

console.log(process.version);

const readable = new Readable({
read() {
process.nextTick(() => this.destroy(new Error('This
*async* error *is not* caught by `pump` in Node < 10')))
// this.destroy(new Error('This *sync* error *is* caught by `pump` in Node < 10'))
},
});

const writable = new Writable({
write(chunk, encoding, done) {
console.log(chunk);
done();
}
})

pump(readable, writable, (ex) => {
console.log('Finished');
console.error(ex); // undefined in Node < 10
});
```

Surprisingly it can be caught by binding directly to the `readable` error event. e.g.

```js
readable.on('error', (ex) => {
console.log('Error handler', ex); // Error
});
```

Which is why I think it might be an issue with `pump`, rather than Node core?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the pump(readable, writable, callback) entry point and reproduce the provided stream example under Node versions before and after 10. Trace how the readable's asynchronous error reaches the callback; done means the callback receives the error consistently for the affected Node versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.