ruby-changes:72529
From: Yusuke <ko1@a...>
Date: Wed, 13 Jul 2022 16:09:29 +0900 (JST)
Subject: [ruby-changes:72529] 1fe6c92603 (master): Specify usable escape sequences in Exception#detailed_message
https://git.ruby-lang.org/ruby.git/commit/?id=1fe6c92603 From 1fe6c926036b3e6956865b56fba52ed242488e42 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Tue, 12 Jul 2022 13:50:04 +0900 Subject: Specify usable escape sequences in Exception#detailed_message An error message is primarily rendered in a terminal emulator, but is also shown in a browser by converting it to a HTML fragment. However, the conversion would be unreasonably difficult if the message includes any escape sequence (such as cursor move or screen clear). This change adds a guideline about escape sequences in `Exception#detailed_message`: * Use widely-supported escape sequences: bold, underline, and basic eight foreground colors (except white and black). * Make the message readable if all escape sequences are ignored. --- error.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/error.c b/error.c index d5721b2eca..0de21aaee9 100644 --- a/error.c +++ b/error.c @@ -1385,6 +1385,28 @@ exc_message(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L1385 * * 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 sequeunces 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. */ static VALUE -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/