Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw Error inside onRetry #79

Open
yokomotod opened this issue Aug 2, 2021 · 0 comments
Open

throw Error inside onRetry #79

yokomotod opened this issue Aug 2, 2021 · 0 comments

Comments

@yokomotod
Copy link

Throwing an error in onRetry seems like a weird behavior to me.

const retry = require("async-retry");

(async () => {
  try {
    await retry(
      (bail, attempt) => {
        throw new Error(`inside error at ${attempt}`);
      },
      {
        onRetry: (e, attempt) => {
          console.error(e.message);
          throw new Error(`onRetry error at ${attempt}`);
        },
      },
    );
  } catch (e) {
    console.error(e.message);
  }
})();

Result:

inside error at 1
onRetry error at 1
inside error at 2
/home/xxxxx/playground.js:12
          throw new Error(`onRetry error at ${attempt}`);
          ^

Error: onRetry error at 2
    at Object.onRetry (/home/xxxxx/playground.js:12:17)
    at onError (/home/xxxxx/node_modules/async-retry/lib/index.js:33:17)
    at RetryOperation.runAttempt [as _fn] (/home/xxxxx/node_modules/async-retry/lib/index.js:43:9)
    at Timeout._onTimeout (/home/xxxxx/node_modules/retry/lib/retry_operation.js:81:10)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

I expected that it caught once without retry like:

inside error at 1
onRetry error at 1
(finish)

otherwise, with retry like:

inside error at 1
inside error at 2
inside error at 3
inside error at 4
inside error at 5
inside error at 6
onRetry error at 6
(finish)

Is this a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant