Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method · added in Ruby 3.2

Exception#detailed_message

exception.detailed_message(highlight: bool, **opt) → string

Processes a string returned by message.

It may add the class name of the exception to the end of the first line. Also, when highlight keyword is true, it adds ANSI escape sequences to make the message bold.

If you override this method, it must be tolerant for unknown keyword arguments. All keyword arguments passed to full_message are delegated to this method.

This method is overridden by did_you_mean and error_highlight to add their information.

A user-defined exception class can also define their own detailed_message method to add supplemental information. When highlight is true, it can return a string containing escape sequences, but use widely-supported ones. It is recommended to limit the following codes:

  • Reset (+\e[0m+)

  • Bold (+\e[1m+)

  • Underline (+\e[4m+)

  • Foreground color except white and black

    • Red (+\e[31m+)

    • Green (+\e[32m+)

    • Yellow (+\e[33m+)

    • Blue (+\e[34m+)

    • Magenta (+\e[35m+)

    • Cyan (+\e[36m+)

Use escape sequences carefully even if highlight is true. Do not use escape sequences to express essential information; the message should be readable even if all escape sequences are ignored.

Ruby version changes

  1. 3.2