caolan / async

Async utilities for node and the browser
http://caolan.github.io/async/
MIT License
28.18k stars 2.41k forks source link

Error propagation - Original error lost #1925

Closed xescuder closed 1 month ago

xescuder commented 11 months ago

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.

nwalters512 commented 11 months ago

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?

xescuder commented 11 months ago

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.

nwalters512 commented 11 months ago

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?

xescuder commented 11 months ago

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

aearly commented 1 month ago

retry does not touch the err object unless you provide an errorFilter option. I'd wager the coercion to [Object object] is happening outside of Async.