Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async errors not caught in Node < 10 #51

Open
richardscarrott opened this issue Jan 8, 2020 · 0 comments
Open

Async errors not caught in Node < 10 #51

richardscarrott opened this issue Jan 8, 2020 · 0 comments

Comments

@richardscarrott
Copy link

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

The Node 8 docs suggest an error is emitted when calling Readable.prototype.destroy, however pump doesn't propagate the error to the callback. e.g.

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.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant