ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "ioquatix (Samuel Williams)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:110038] [Ruby master Feature#18296] Custom exception formatting should override `Exception#full_message`.
Date: Fri, 23 Sep 2022 07:42:14 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-99289.20220923074213.3344@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18296.20211110114932.3344@ruby-lang.org

Issue #18296 has been updated by ioquatix (Samuel Williams).

Status changed from Open to Closed

I'm satisfied that this has been fully addressed and the design is much better. Thanks everyone.

----------------------------------------
Feature #18296: Custom exception formatting should override `Exception#full_message`.
https://bugs.ruby-lang.org/issues/18296#change-99289

* Author: ioquatix (Samuel Williams)
* Status: Closed
* Priority: Normal
----------------------------------------
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/

      parent reply	other threads:[~2022-09-23  7:42 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 ` [ruby-core:106030] " mame (Yusuke Endoh)
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 ` ioquatix (Samuel Williams) [this message]

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-99289.20220923074213.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).