You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using pRetry with retry count >= 1, the stack trace of the original calling function is not preserved, which complicates debugging, especially if the code wasn't written with this behavior in mind.
Example:
// pRetryStack.mjsimportpRetryfrom'p-retry';asyncfunctionfoo1(){returnawaitfoo2();}asyncfunctionfoo2(){returnawaitpRetry(async()=>{thrownewError('foo2 failed');},{retries: 1},);}// This doesn't lose the stack trace// async function foo2() {// throw new Error('foo2 failed');// }asyncfunctionmain(){try{awaitfoo1();}catch(err){console.error(err);}}main();
Running node pRetryStack.mjs
Would print:
Error: foo2 failed
at pRetry.retries (file:///****/pRetryStack.mjs:9:29)
at RetryOperation._fn (/****/node_modules/p-retry/index.js:50:18)
at Timeout._onTimeout (/****/node_modules/p-retry/node_modules/retry/lib/retry_operation.js:85:10)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
attemptNumber: 4,
retriesLeft: 0
}
While the commented out code would print:
Error: foo2 failed
at foo2 (file:///****/pRetryStack.mjs:12:11)
at foo1 (file:///****/pRetryStack.mjs:4:18)
at main (file:///****/pRetryStack.mjs:17:15)
at file:///****/pRetryStack.mjs:23:1
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:106:12)
Suggestion:
One possible solution could be to capture the original stack trace and add it as a property to the error, making it easier to trace the origin of the issue while retaining the retry context.
The text was updated successfully, but these errors were encountered:
When using pRetry with retry count >= 1, the stack trace of the original calling function is not preserved, which complicates debugging, especially if the code wasn't written with this behavior in mind.
Example:
Running
node pRetryStack.mjs
Would print:
While the commented out code would print:
Suggestion:
One possible solution could be to capture the original stack trace and add it as a property to the error, making it easier to trace the origin of the issue while retaining the retry context.
The text was updated successfully, but these errors were encountered: