From: "headius (Charles Nutter) via ruby-core" Date: 2024-02-27T19:30:33+00:00 Subject: [ruby-core:116979] [Ruby master Feature#20275] Avoid extra backtrace entries for rescue and ensure Issue #20275 has been updated by headius (Charles Nutter). JRuby also does not have a separate frame for rescues and ensures and we support removing these entries from backtraces. ---------------------------------------- Feature #20275: Avoid extra backtrace entries for rescue and ensure https://bugs.ruby-lang.org/issues/20275#change-107027 * Author: Eregon (Benoit Daloze) * Status: Open * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- From https://bugs.ruby-lang.org/issues/19117#note-48: ```ruby def raise_nested_exceptions raise "First error" rescue begin raise "Second error" rescue raise "Third error" end end raise_nested_exceptions ``` Current: ``` -:7:in 'Object#raise_nested_exceptions': Third error (RuntimeError) from -:4:in 'Object#raise_nested_exceptions' from -:1:in 'Object#raise_nested_exceptions' from -:11:in '
' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '
' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '
' ``` The above repeated backtrace entries for `Object#raise_nested_exceptions` are because of CRuby implementation details. It seems best to hide them because they do not help understanding the program, and semantically there is no (method or proc) call on line 1 or 4. Proposed: ``` -:7:in 'Object#raise_nested_exceptions': Third error (RuntimeError) from -:11:in '
' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '
' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '
' ``` We can see TruffleRuby and JRuby already behave this way, most likely because they do not use an extra frame for `rescue`. It is definitely useful to have the same backtrace on different Ruby implementations as some tests rely on this. TruffleRuby 23.1.2: ``` -:7:in `raise_nested_exceptions': Third error (RuntimeError) from -:11:in `
' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `
' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `
' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7
at -:11 RuntimeError: Second error raise_nested_exceptions at -:5
at -:11 RuntimeError: First error raise_nested_exceptions at -:2
at -:11 ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/