Skip to content

[FEAT]: Simplify use-case "retry on errors" #47

@manuelmeurer

Description

@manuelmeurer

Describe the need

I often use Octopoller to run some code that might raise a specific error (or one of multiple specific errors) and retry a few times if that errors happens:

MyError = Class.new(StandardError)

begin
  Octopoller.poll retries: 3 do
    # Do something that might raise MyError.
  rescue MyError => cause_error
    :re_poll
  end
rescue Octopoller::TooManyAttemptsError => error
  # To access the error, which caused the Octopoller::TooManyAttemptsError,
  # I must access `cause_error`, since `error.cause` is nil.
end

This is quite ugly and hard to read, though.

I propose we add a errors parameter that lets us do this instead:

MyError = Class.new(StandardError)

begin
  Octopoller.poll retries: 3, errors: [MyError] do
    # Do something that might raise MyError.
    # It will be retried 3 times automatically.
  end
rescue Octopoller::TooManyAttemptsError => error
  # Here I can access the error, which caused the Octopoller::TooManyAttemptsError,
  # via `error.cause`.
end

Much easier to read and the cause of Octopoller::TooManyAttemptsError (and Octopoller::TimeoutError) is set properly.

SDK Version

No response

API Version

No response

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is being looked at and prioritizedType: FeatureNew feature or request

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions