kamui/retriable

Error subclasses are not handled when matching patterns

apurvis opened this issue · 1 comments

code to recreate:

class SomeOtherError < StandardError; end

RETRY_PARAMS = {
  on: { StandardError => /pattern/ },
  on_retry: Proc.new do |exception, try, elapsed_time, next_interval|
    puts "#{exception.class}: '#{exception.message}' - #{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try."
    puts exception.backtrace.join("\n")
  end
}

Retriable.retriable(RETRY_PARAMS) do
  raise SomeOtherError.new('paxern')
end

# Block retries, even though the pattern is not matched

Retriable.retriable(RETRY_PARAMS) do
  raise StandardError.new('paxern')
end

# Block does not retry

I would expect SomeOtherError to have its message matched against /pattern/, but this does not happen. The gem instead tries to find the pattern with on[StandardError], comes up with nothing, decides it is an empty list, and retries even when the pattern is not matched.

kamui commented

Implemented in #24, thanks @apurvis!