-
Notifications
You must be signed in to change notification settings - Fork 215
workbook.write
throws instead of calling callback
#148
Comments
I'm planning on re-working the whole error handling in the next major version which I'm working on this winter. As a temporary solution, you could wrap the |
This is not as simple, users cannot workaround the current issue by using a try/catch around A simple reproduction case is the following one. Try it and you'll see that you never enter the catch clause of the try/catch block. That's why at least calling the callback with the error seems mandatory :) const promise = new Promise(() => setTimeout(() => BOOM(), 1000));
try {
promise.catch(err => { throw err });
} catch (err) {
// This is never reached!
console.log('Hey, I caught the error! ' + err.message);
} |
oh, right. I'll change this to a bug and get a fix put into the next patch release |
Awesome, thanks a lot ! |
Fix has now been pushed to NPM with version 1.3.1 |
Function
workbook.write
ends with these lines:excel4node/source/lib/workbook/workbook.js
Lines 194 to 196 in 1c4a7bf
Since we are inside a promise rejection, it means this error thrown will never be caught by anyone, which just crashes nodejs with an
UnhandledPromiseRejectionWarning
.The solution is to call the callback if it was provided, or just log the error and return gracefully if there is no callback.
For the record, the error we got in production is:
The text was updated successfully, but these errors were encountered: