
Issue #20484 has been updated by zverok (Victor Shepelev). Honestly, it is no different than any name used in a branch that wasn’t tested. E.g. if you have this: ```ruby if foo OneClass.new else OtherClass.new end ``` ...and the `else` branch wasn’t covered by tests, and the `OtherClass` isn’t defined, then it will struck in production. The rescue clauses can be seen as kind of “syntax sugar” upon this: ```ruby # ... rescue => e case e when SomeClass # ... when OtherClass # ... else # ... end end ``` Which makes it more obvious that unless you ran into the `rescue` branch, any name inside it wouldn’t be evaluated, and no name errors would be caught. So the common answer is “it should be covered by testing and/or static code analysis.” Though theoretically, “opt-in forced resolution of everything that looks like a module name” might be an interesting idea to play with (but it probably shouldn’t be limited to `rescue` blocks). ---------------------------------------- Feature #20484: A new pragma for eager resolution of classes referenced in rescue clauses. https://bugs.ruby-lang.org/issues/20484#change-108252 * Author: jfrisby (Jon Frisby) * Status: Feedback ---------------------------------------- I've been using Ruby for 20 years, and just today learned (the hard way) that the class name(s) referenced in a `rescue` clause are not resolved until an exception occurs. Upon reflection, this behavior probably makes sense in a lot of situations. Late resolution may simplify code loading for the developer. I would, however, love to see an opt-in feature (a la `frozen-string-literal`) to force resolution when the code is loaded/parsed. -- https://bugs.ruby-lang.org/