From: "Eregon (Benoit Daloze) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "Eregon (Benoit Daloze)" <noreply@ruby-lang.org>
Subject: [ruby-core:116819] [Ruby master Feature#20275] Avoid extra backtrace entries for rescue and ensure
Date: Sat, 17 Feb 2024 10:41:24 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-20275.20240217104124.772@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20275.20240217104124.772@ruby-lang.org
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/
______________________________________________
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/
next parent reply other threads:[~2024-02-17 10:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-17 10:41 Eregon (Benoit Daloze) via ruby-core [this message]
2024-02-17 10:45 ` [ruby-core:116820] [Ruby master Feature#20275] Avoid extra backtrace entries for rescue and ensure Eregon (Benoit Daloze) via ruby-core
2024-02-17 11:57 ` [ruby-core:116824] " mame (Yusuke Endoh) via ruby-core
2024-02-19 1:30 ` [ruby-core:116835] " ko1 (Koichi Sasada) via ruby-core
2024-02-27 3:57 ` [ruby-core:116966] " matz (Yukihiro Matsumoto) via ruby-core
2024-02-27 19:30 ` [ruby-core:116979] " headius (Charles Nutter) via ruby-core
2024-02-28 4:22 ` [ruby-core:116988] " mame (Yusuke Endoh) via ruby-core
2024-03-21 20:08 ` [ruby-core:117287] " Eregon (Benoit Daloze) via ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-20275.20240217104124.772@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
--cc=noreply@ruby-lang.org \
--cc=ruby-core@ml.ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).