Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
Exception#detailed_message
static VALUE
exc_detailed_message(int argc, VALUE *argv, VALUE exc)
{
VALUE opt;
rb_scan_args(argc, argv, "0:", &opt);
VALUE highlight = check_highlight_keyword(opt, 0);
extern VALUE rb_decorate_message(const VALUE eclass, VALUE emesg, int highlight);
return rb_decorate_message(CLASS_OF(exc), rb_get_message(exc), RTEST(highlight));
}
Returns the message string with enhancements:
-
Includes the exception class name in the first line.
-
If the value of keyword
highlightistrue, includes bolding and underlining ANSI codes (see below) to enhance the appearance of the message.
Examples:
begin 1 / 0 rescue => x p x.message p x.detailed_message # Class name added. p x.detailed_message(highlight: true) # Class name, bolding, and underlining added. end
Output:
"divided by 0" "divided by 0 (ZeroDivisionError)" "\e[1mdivided by 0 (\e[1;4mZeroDivisionError\e[m\e[1m)\e[m"
This method is overridden by some gems in the Ruby standard library to add information:
An overriding method must be tolerant of passed keyword arguments, which may include (but may not be limited to):
-
:highlight. -
:did_you_mean. -
:error_highlight. -
:syntax_suggest.
An overriding method should also be careful with ANSI code enhancements; see Messages.
Ruby version changes
-
3.2
-
Exception#detailed_messagehas been added. The default error printer calls this method on theExceptionobject instead of message. [Feature #18564]
-