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

Rescue through Set of errors not working #2572

Closed
brauliobo opened this issue Jan 17, 2022 · 3 comments
Closed

Rescue through Set of errors not working #2572

brauliobo opened this issue Jan 17, 2022 · 3 comments
Assignees
Milestone

Comments

@brauliobo
Copy link
Contributor

The following code:

RETRIABLE_ERRORS = Set.new([
  ::Mechanize::ResponseCodeError,
  ::Mechanize::ResponseReadError,
])

def call method, url, *args
  mechanize.send method, url, *args                                                                                                                                                                        
rescue *RETRIABLE_ERRORS => e
end

Returns the error TypeError: class or module required for rescue clause on truffleruby but works on MRI

@brauliobo brauliobo changed the title Rescue through array of constants not working Rescue through array of errors not working Jan 17, 2022
@eregon
Copy link
Member

eregon commented Jan 18, 2022

Thanks for the report, simpler repro with no dependencies:

require 'set'

RETRIABLE_ERRORS = Set.new([
  RuntimeError,
  ArgumentError,
])

def call
  raise "oops"
rescue *RETRIABLE_ERRORS => e
  p e
end

call

It works fine if an Array is used instead of the Set.
A Set of exceptions like here seems rather inefficient since it will cause to iterate the set on every exception.

@eregon eregon self-assigned this Jan 18, 2022
@eregon eregon changed the title Rescue through array of errors not working Rescue through Set of errors not working Jan 18, 2022
@eregon eregon added this to the 22.1.0 milestone Jan 18, 2022
@brauliobo
Copy link
Contributor Author

thanks eregon, I'll switch to array

@eregon
Copy link
Member

eregon commented Jan 18, 2022

I have a fix coming BTW, it's literally changing a true to false to use to_a instead of to_ary for coercion.

graalvmbot pushed a commit that referenced this issue Jan 18, 2022
graalvmbot pushed a commit that referenced this issue Jan 18, 2022
eregon added a commit to ruby/spec that referenced this issue Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants