From: "Eregon (Benoit Daloze)" Date: 2021-11-10T11:57:18+00:00 Subject: [ruby-core:106009] [Ruby master Bug#18296] Custom exception formatting should override `Exception#full_message`. Issue #18296 has been updated by Eregon (Benoit Daloze). I think this is a clean and simple proposal/fix, which enables users to choose whether they want that extra information on a per-call to #full_message-basis. As a side effect it also enables DidYouMean and ErrorHighlight to e.g. look at the value of the `highlight:` keyword argument value and decide whether to use ANSI escape sequences. cc @mame @yuki24 I think this is the best way to integrate ErrorHighlight and DidYouMean cleanly. Overriding `message` was always a shortcut/hack (because it doesn't let the user choose what they want, only globally via `--disable` which is not good enough), and I believe this is the way to fix it. ---------------------------------------- Bug #18296: Custom exception formatting should override `Exception#full_message`. https://bugs.ruby-lang.org/issues/18296#change-94562 * 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_highlighter` 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 class Formatter def full_message(highlight:, did_you_mean: true, **options) buffer = super(highlight: highlight, **options).dup buffer << "extra stuff" end end end module ErrorHighlight class Formatter def full_message(highlight:, error_highlight: true, **options) # same as above end end end ``` -- https://bugs.ruby-lang.org/ Unsubscribe: