async
async copied to clipboard
Error propagation - Original error lost
Using async retry function some errors are wrapped incorrectly. The error thrown is a string with [object Object], so we're losing original error.
This happens for example with some APIs that are throwing an error with error.errorMessages field and not error.message, as expected by current 3.0.5 async release.
Can you provide a self-contained reproduction or a failing test? Are your errors passing the instanceof Error
check? That is, are they actually errors, or just random objects?
Sorry, but it's a project which I can't share it directly. The error is generated from jira.js and Xray GraphQL API clients. Anyway, I've debugged the code to see that your promise callback is getting the error from these APIs, but the condition is not Error instance and not message field exists. I think the problem is that the asyn callback should bypass directly the err, so it's managed by the code.
I'd recommend looking into why that conditional is failing. It's unconventional to throw or reject with a non-Error object; maybe you can update your code or your dependencies to reject with an Error
or a subclass of it?
I'm catching these exceptions and wrapping them with an Error.