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

Promisified version of pipeline() doesn't throw the same error that's sent to pipeline()'s error handler. #26985

Closed
spaghetti-is-pasta opened this issue Mar 29, 2019 · 2 comments

Comments

@spaghetti-is-pasta
Copy link

  • Version: v11.13.0
  • Platform: Linux 3.10.0-693.21.1.el7.x86_64
  • Subsystem: stream

This works as expected:

const fs = require('fs');
const { pipeline } = require('stream')

pipeline(
    process.stdin,
    fs.createWriteStream("/un-writable-file"),
    e => console.error("this should happen")
);

// prints "this should happen"

However, this equivalent, using the promisified version of pipeline doesn't throw the same error:

const fs = require('fs');
const stream = require('stream')
const { promisify } = require('util');
const pipelinePromise = promisify(stream.pipeline);

(async () => {

   try {
      pipelinePromise(
         process.stdin,
         fs.createWriteStream("/un-writable-file")
      )
   }
   catch (e) {
      console.log("this should happen");
   }

})()

// An unhandled exception is thrown. "this should happen" is *not* printed.

I believe that if the error handler was properly called using pipeline(), then the promisified version should behave the same, but with the error being thrown.

@Hakerh400
Copy link
Contributor

It should be await pipelinePromise(...)

@spaghetti-is-pasta
Copy link
Author

duh, thanks!

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

2 participants