[#109095] [Ruby master Misc#18888] Migrate ruby-lang.org mail services to Google Domains and Google Workspace — "shugo (Shugo Maeda)" <noreply@...>
Issue #18888 has been reported by shugo (Shugo Maeda).
16 messages
2022/06/30
[ruby-core:108791] [Ruby master Bug#18170] Exception#inspect should not include newlines
From:
"st0012 (Stan Lo)" <noreply@...>
Date:
2022-06-07 09:25:27 UTC
List:
ruby-core #108791
Issue #18170 has been updated by st0012 (Stan Lo).
I think this change will affect many users' tests because test frameworks generally use exceptions for assertion messages.
For example, this is how [test-unit](https://github.com/test-unit/test-unit) implements [assert_block](https://github.com/test-unit/test-unit/blob/e6698ddef4a08b3744f19fe1ef6cc13e704b966e/lib/test/unit/assertions.rb#L53-L63)
```
def assert_block(message="assert_block failed.")
_wrap_assertion do
if (! yield)
options = {}
if message.respond_to?(:user_message)
options[:user_message] = message.user_message
end
raise AssertionFailedError.new(message.to_s, options)
end
end
end
```
You can see it takes a custom message and then pass it into an exception, which will later be used to print failure info when the test failed.
And many developers (myself included) use multiple lines to format failure messages. [Example from ruby/debug](https://github.com/ruby/debug/blob/b0d34c629047375290c4d5f8f0f3c243bdc79e67/test/support/utils.rb#L15-L51). So with this change, formatted test messages like those will be squashed into 1 line and become hard to read.
----------------------------------------
Bug #18170: Exception#inspect should not include newlines
https://bugs.ruby-lang.org/issues/18170#change-97862
* 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")
#=>
# #<StandardError: foo
# bar>
```
I expect `#inspect` returns a one-line string. How about returning `#<StandardError: "foo\nbar">` 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
#=>
# #<Foo:0x00007f15aeb4ba48 @exception=#<NameError: undefined local variable or method `exampl' for #<Foo:0x00007f15aeb4ba48 ...>
#
# @exception = begin; exampl; rescue Exception; $!; end
# ^^^^^^
# Did you mean? example>>
```
This issue was originally found by @ioquatix
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>