From: "mame (Yusuke Endoh)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:106030] [Ruby master Bug#18296] Custom exception formatting should override `Exception#full_message`.
Date: Thu, 11 Nov 2021 14:06:45 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-94620.20211111140644.3344@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18296.20211110114932.3344@ruby-lang.org
Issue #18296 has been updated by mame (Yusuke Endoh).
Eregon (Benoit Daloze) wrote in #note-7:
> mame (Yusuke Endoh) wrote in #note-6:
> > Does this proposal include that the ruby interpreter should use `#full_message` to show the error information? This is an incompatibility, is it acceptable?
>
> Yes, let's fix that.
Thanks. I think that this is the most important part of this proposal. It should be clearly explained in the description. Actually, I don't think that the implementation of error_highlight and did_you_mean is so important.
I have no strong opinion, but if the change is accepted, I will be happy to change the implementation of error_highlight.
Also, the motivation of this proposal is not clear to me. The implementation of error_highlight and did_you_mean is indeed dirty, but I don't see how it matters to end users. I guess it may matter when a user calls `Exception#message`, but anyway, it should also be clearly explained the description.
@eregon changed the code snippet in the description, which made the proposal clear to me. However, in regard to the backtrace, eregon's proof-of-concept looks much more difficult than the code in the original description. I believe that it would be good to implement it and to confirm that the proposal actually works before the discussion.
Because this ticket started with unclear description, and the discussion so far is also unclear. How about closing this ticket and creating a new ticket with a clear explanation of the motivation, the proposal, and a proof-of-concept patch if any?
----------------------------------------
Bug #18296: Custom exception formatting should override `Exception#full_message`.
https://bugs.ruby-lang.org/issues/18296#change-94620
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
After discussing with @eregon, we came to the conclusion that the current implementation of `did_you_mean` and `error_highlight` could avoid many issues by using `Exception#full_message`.
We propose to introduce a more nuanced interface:
```ruby
class Exception
def full_message(highlight: bool, order: [:top or :bottom], **options)
# ...
end
end
module DidYouMean
module Formatter
def full_message(highlight:, did_you_mean: true, **options)
buffer = super(highlight: highlight, **options).dup
buffer << "extra stuff"
end
end
end
Exception.prepend DidYouMean::Formatter
module ErrorHighlight
module Formatter
def full_message(highlight:, error_highlight: true, **options)
# same as above
end
end
end
Exception.prepend ErrorHighlight::Formatter
```
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2021-11-11 14:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-10 11:49 [ruby-core:106008] [Ruby master Bug#18296] Custom exception formatting should override `Exception#full_message` ioquatix (Samuel Williams)
2021-11-10 11:57 ` [ruby-core:106009] " Eregon (Benoit Daloze)
2021-11-10 11:58 ` [ruby-core:106010] " ioquatix (Samuel Williams)
2021-11-11 5:49 ` [ruby-core:106021] " mame (Yusuke Endoh)
2021-11-11 11:07 ` [ruby-core:106027] " Eregon (Benoit Daloze)
2021-11-11 11:38 ` [ruby-core:106028] " Eregon (Benoit Daloze)
2021-11-11 14:06 ` mame (Yusuke Endoh) [this message]
2021-11-14 12:40 ` [ruby-core:106051] " Eregon (Benoit Daloze)
2021-11-15 4:19 ` [ruby-core:106063] " yuki24 (Yuki Nishijima)
2021-11-18 7:34 ` [ruby-core:106124] [Ruby master Feature#18296] " matz (Yukihiro Matsumoto)
2021-11-23 19:51 ` [ruby-core:106229] " Dan0042 (Daniel DeLorme)
2021-12-15 18:15 ` [ruby-core:106699] " Dan0042 (Daniel DeLorme)
2021-12-15 20:49 ` [ruby-core:106700] " ioquatix (Samuel Williams)
2022-09-23 7:42 ` [ruby-core:110038] " ioquatix (Samuel Williams)
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.journal-94620.20211111140644.3344@ruby-lang.org \
--to=ruby-core@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).