From: "mame (Yusuke Endoh)" Date: 2021-10-25T08:59:17+00:00 Subject: [ruby-core:105778] [Ruby master Bug#18170] Exception#inspect should not include newlines Issue #18170 has been updated by mame (Yusuke Endoh). We discussed this ticket at the dev-meeting, and matz basically accepted as above. The approved spec is very hacky. Only when the message includes new lines, `Exception#inspect` applies `inspect` to the message. Otherwise, it embeds the message as is. ``` p StandardError.new("foo\nbar") #=> # p StandardError.new("foo bar") #=> # p StandardError.new("foo\\bar") #=> # ``` Note that there is no space between the colon and the double quote in the first line. This is a mark showing whether `inspect` is used. ``` p StandardError.new("foo\nbar") #=> # p StandardError.new('"foo\nbar"') #=> # ``` Parsing the result of `#inspect` is never recommended, though. I'll update my PR later to follow the approved spec. ---------------------------------------- Bug #18170: Exception#inspect should not include newlines https://bugs.ruby-lang.org/issues/18170#change-94292 * Author: mame (Yusuke Endoh) * Status: Assigned * Priority: Normal * Assignee: mame (Yusuke Endoh) * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- Is this intentional? ``` p StandardError.new("foo\nbar") #=> # # ``` I expect `#inspect` returns a one-line string. How about returning `#` or something? Recently, multi-line error messages have been increasing by the introduction of did_you_mean and error_highlight. Printing an object that contains such an exception leads to a tricky output: ``` class Foo def initialize @exception = begin; exampl; rescue Exception; $!; end end def example end end p Foo.new #=> # # # # @exception = begin; exampl; rescue Exception; $!; end # ^^^^^^ # Did you mean? example>> ``` This issue was originally found by @ioquatix -- https://bugs.ruby-lang.org/ Unsubscribe: