[ruby-core:116819] [Ruby master Feature#20275] Avoid extra backtrace entries for rescue and ensure

Issue #20275 has been reported by Eregon (Benoit Daloze). ---------------------------------------- Feature #20275: Avoid extra backtrace entries for rescue and ensure https://bugs.ruby-lang.org/issues/20275 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal ---------------------------------------- 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` We can see TruffleRuby 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 lots of tests rely on this. TruffleRuby 23.1.2: ``` -:7:in `raise_nested_exceptions': Third error (RuntimeError) from -:11:in `<main>' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `<main>' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `<main>' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7 <main> at -:11 RuntimeError: Second error raise_nested_exceptions at -:5 <main> at -:11 RuntimeError: First error raise_nested_exceptions at -:2 <main> at -:11 ``` -- https://bugs.ruby-lang.org/

Issue #20275 has been updated by Eregon (Benoit Daloze). Same thing for `ensure`: ```ruby begin raise ensure p caller(0) end ``` On CRuby master: ``` ["-:4:in '<main>'", "-:4:in '<main>'"] ``` On CRuby 3.2: ``` ["-:4:in `ensure in <main>'", "-:4:in `<main>'"] ``` Proposed: ``` ["-:4:in '<main>'"] ``` Already the case on TruffleRuby and JRuby (except the quotes which have not changed yet of course): ``` ["-:4:in `<main>'"] ``` ---------------------------------------- Feature #20275: Avoid extra backtrace entries for rescue and ensure https://bugs.ruby-lang.org/issues/20275#change-106844 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal ---------------------------------------- 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` We can see TruffleRuby 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 lots of tests rely on this. TruffleRuby 23.1.2: ``` -:7:in `raise_nested_exceptions': Third error (RuntimeError) from -:11:in `<main>' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `<main>' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `<main>' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7 <main> at -:11 RuntimeError: Second error raise_nested_exceptions at -:5 <main> at -:11 RuntimeError: First error raise_nested_exceptions at -:2 <main> at -:11 ``` -- https://bugs.ruby-lang.org/

Issue #20275 has been updated by mame (Yusuke Endoh). Assignee set to ko1 (Koichi Sasada) ---------------------------------------- Feature #20275: Avoid extra backtrace entries for rescue and ensure https://bugs.ruby-lang.org/issues/20275#change-106849 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) ---------------------------------------- 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` We can see TruffleRuby 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 `<main>' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `<main>' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `<main>' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7 <main> at -:11 RuntimeError: Second error raise_nested_exceptions at -:5 <main> at -:11 RuntimeError: First error raise_nested_exceptions at -:2 <main> at -:11 ``` -- https://bugs.ruby-lang.org/

Issue #20275 has been updated by ko1 (Koichi Sasada). Assignee changed from ko1 (Koichi Sasada) to matz (Yukihiro Matsumoto) I don't have any opinion so I leave it on Matz. ---------------------------------------- Feature #20275: Avoid extra backtrace entries for rescue and ensure https://bugs.ruby-lang.org/issues/20275#change-106860 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 `<main>' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `<main>' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `<main>' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7 <main> at -:11 RuntimeError: Second error raise_nested_exceptions at -:5 <main> at -:11 RuntimeError: First error raise_nested_exceptions at -:2 <main> at -:11 ``` -- https://bugs.ruby-lang.org/

Issue #20275 has been updated by matz (Yukihiro Matsumoto). I agree with removing `ensure in` and `rescue in` entries from backtraces. Matz. ---------------------------------------- Feature #20275: Avoid extra backtrace entries for rescue and ensure https://bugs.ruby-lang.org/issues/20275#change-107010 * 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 `<main>' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `<main>' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `<main>' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7 <main> at -:11 RuntimeError: Second error raise_nested_exceptions at -:5 <main> at -:11 RuntimeError: First error raise_nested_exceptions at -:2 <main> at -:11 ``` -- https://bugs.ruby-lang.org/

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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 `<main>' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `<main>' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `<main>' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7 <main> at -:11 RuntimeError: Second error raise_nested_exceptions at -:5 <main> at -:11 RuntimeError: First error raise_nested_exceptions at -:2 <main> at -:11 ``` -- https://bugs.ruby-lang.org/

Issue #20275 has been updated by mame (Yusuke Endoh). I am in favor of this change, but I do not plan to write a patch and estimate its impact. Someone who wants this, please do it. I recommend doing this earlier. Since it is incompatible, it may be too late closer to the upcoming release. ---------------------------------------- Feature #20275: Avoid extra backtrace entries for rescue and ensure https://bugs.ruby-lang.org/issues/20275#change-107037 * 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 `<main>' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `<main>' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `<main>' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7 <main> at -:11 RuntimeError: Second error raise_nested_exceptions at -:5 <main> at -:11 RuntimeError: First error raise_nested_exceptions at -:2 <main> at -:11 ``` -- https://bugs.ruby-lang.org/

Issue #20275 has been updated by Eregon (Benoit Daloze). Assignee changed from matz (Yukihiro Matsumoto) to Eregon (Benoit Daloze) PR: https://github.com/ruby/ruby/pull/10325 ---------------------------------------- Feature #20275: Avoid extra backtrace entries for rescue and ensure https://bugs.ruby-lang.org/issues/20275#change-107413 * Author: Eregon (Benoit Daloze) * Status: Open * Assignee: Eregon (Benoit Daloze) ---------------------------------------- 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:1:in 'Object#raise_nested_exceptions' from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 '<main>' -:5:in 'Object#raise_nested_exceptions': Second error (RuntimeError) from -:11:in '<main>' -:2:in 'Object#raise_nested_exceptions': First error (RuntimeError) from -:11:in '<main>' ``` 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 `<main>' -:5:in `raise_nested_exceptions': Second error (RuntimeError) from -:11:in `<main>' -:2:in `raise_nested_exceptions': First error (RuntimeError) from -:11:in `<main>' ``` JRuby 9.4.5.0: ``` RuntimeError: Third error raise_nested_exceptions at -:7 <main> at -:11 RuntimeError: Second error raise_nested_exceptions at -:5 <main> at -:11 RuntimeError: First error raise_nested_exceptions at -:2 <main> at -:11 ``` -- https://bugs.ruby-lang.org/
participants (5)
-
Eregon (Benoit Daloze)
-
headius (Charles Nutter)
-
ko1 (Koichi Sasada)
-
mame (Yusuke Endoh)
-
matz (Yukihiro Matsumoto)