From: "ioquatix (Samuel Williams)" Date: 2021-10-26T08:59:02+00:00 Subject: [ruby-core:105804] [Ruby master Bug#18170] Exception#inspect should not include newlines Issue #18170 has been updated by ioquatix (Samuel Williams). @mame thanks for all your work on this issue. > Incompatibility. In general, users should not depend on the return value of #inspect. That being said, we don't want to introduce incompatibility unnecessarily. According to my PR, the simple approach actually required some modification to tests, so the incompatibility issue is not imaginary but real. We'd avoid the hassle here. We tested the change with the entire RSpec code base and there was no failure. Because RSpec has specific error matching predicates which match the error, not the output of inspect. I imagine the same is true for Minitest and similar systems. I can't imagine there would be any systems that will directly match output of `Exception#inspect` in actual real world tests, and even if there are, they are easily fixed. Regarding the Ruby test failures, maybe the problem is that the test of the exact format is incorrect. Since we don't expect users to depend on exact format, why do our tests depend on the exact format? We can rework these tests to be more flexible. > we don't want to introduce incompatibility unnecessarily I'm willing to break compatibility if it means a simpler and more consistent implementation, especially longer term. To this end, the current proposed change seems okay to me, but I wouldn't introduce any changes to spacing to determine the difference. As you said, we don't want users to parse the result of inspect, but by introducing spacing changes, you are indicating some change. Such spacing is also inconsistent with (all?) other implementations of `#inspect`. ---------------------------------------- Bug #18170: Exception#inspect should not include newlines https://bugs.ruby-lang.org/issues/18170#change-94322 * 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: