async icon indicating copy to clipboard operation
async copied to clipboard

Error propagation - Original error lost

Open xescuder opened this issue 1 year ago • 4 comments

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.

xescuder avatar Nov 07 '23 17:11 xescuder

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?

nwalters512 avatar Nov 07 '23 18:11 nwalters512

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.

xescuder avatar Nov 07 '23 20:11 xescuder

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?

nwalters512 avatar Nov 07 '23 20:11 nwalters512

I'm catching these exceptions and wrapping them with an Error.

xescuder avatar Nov 08 '23 15:11 xescuder