Project

General

Profile

Actions

Feature #18296

closed

Custom exception formatting should override `Exception#full_message`.

Added by ioquatix (Samuel Williams) about 3 years ago. Updated about 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:106008]

Description

After discussing with @Eregon (Benoit Daloze), 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:

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

Related issues 4 (0 open4 closed)

Related to Ruby master - Bug #18170: Exception#inspect should not include newlinesClosedmame (Yusuke Endoh)Actions
Related to Ruby master - Feature #18194: No easy way to format exception messages per thread/fiber scheduler context.Closedmame (Yusuke Endoh)Actions
Related to Ruby master - Feature #18370: Call Exception#full_message to print exceptions reaching the top-levelClosedActions
Related to Ruby master - Feature #18438: Add `Exception#additional_message` to show additional error informationClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0