Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

throw callback error in Promise #54

Closed
lemures-t opened this issue May 4, 2018 · 2 comments
Closed

throw callback error in Promise #54

lemures-t opened this issue May 4, 2018 · 2 comments

Comments

@lemures-t
Copy link

lemures-t commented May 4, 2018

Hi. Now I need to throw the error, which sometimes occurs in webpack compiler's callback, to terminate the node process.

webpack(webpackConfig, (err, stats) => {
  if (err) throw err
  // ...
})

But UnhandledPromiseRejectionWarning was received, indicating the error thrown from callback was wrapped in promise chain and the node process was not terminated as expected. After debugging, I found the following code triggered the warning.

attachAfterEmitHook(compiler, (compilation, cb) => {
  this.finalizeRelease(compilation).then(() => cb())
});

Error thrown in cb was wrapped in this.finalizeRelease promise chain. Would you mind calling the cb in setTimeout method to throw out the possible error from promise chain, like:

this.finalizeRelease(compilation).then(() => {
  setTimeout(function(){
    cb()
  })
})

many thanks

@jan-auer
Copy link
Member

jan-auer commented May 4, 2018

Two thoughts here:

  1. In order to end the node process, you could also call process.exit(1).
  2. Putting this in a timeout would simply create a globally unhandled exception in Node, which is in no way better than an unhandled promise rejection (except for different console output).

You should probably consider a mechanism other than throwing to end the compilation. Also note that by the time this happens, a release has already been created on Sentry (and thus symbols uploaded), which might be confusing if your process dies afterwards.

@jan-auer jan-auer closed this as completed May 4, 2018
@lemures-t
Copy link
Author

@jan-auer We have to exit the process since the failure of some other plugins or procedures may cause problems in our web app. But still many thx. I understand what you mean.

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

No branches or pull requests

2 participants