[#106341] [Ruby master Bug#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" } — dorianmariefr <noreply@...>
Issue #18369 has been reported by dorianmariefr (Dorian Mari辿).
14 messages
2021/11/30
[#106351] [Ruby master Bug#18371] Release branches (release information in general) — "tenderlovemaking (Aaron Patterson)" <noreply@...>
Issue #18371 has been reported by tenderlovemaking (Aaron Patterson).
7 messages
2021/11/30
[ruby-core:106003] [Ruby master Bug#18170] Exception#inspect should not include newlines
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-11-10 11:03:19 UTC
List:
ruby-core #106003
Issue #18170 has been updated by Eregon (Benoit Daloze).
I've been thinking about this again, and I'm not sure if
```
#<Foo:0x00007f15aeb4ba48 @exception=#<NameError: undefined local variable or method `exampl' for #<Foo:0x00007f15aeb4ba48 ...>
@exception = begin; exampl; rescue Exception; $!; end
^^^^^^
Did you mean? example>>
```
or
```
#<Foo:0x00007f15aeb4ba48 @exception=#<NameError: "undefined local variable or method `exampl' for #<Foo:0x00007f15aeb4ba48 ...>\n @exception = begin; exampl; rescue Exception; $!; end\n ^^^^^^\nDid you mean? example">>
```
is better.
The object's inspect is unreadable in both cases anyway.
For readability of the error, I believe the first is better.
And if the error was shown alone (common case, e.g. if an exception is shown in IRB or with `p exception`), the first is clearly much better:
```
#<NameError: undefined local variable or method `exampl' for #<Foo:0x00007f15aeb4ba48 ...>
@exception = begin; exampl; rescue Exception; $!; end
^^^^^^
Did you mean? example>
```
vs
```
#<NameError: "undefined local variable or method `exampl' for #<Foo:0x00007f15aeb4ba48 ...>\n @exception = begin; exampl; rescue Exception; $!; end\n ^^^^^^\nDid you mean? example>
```
(that's completely unreadable)
I think needing to read the `inspect` of an object containing an exception is pretty rare, and not worth making `Exception#inspect` less readable (which can be very useful for debugging).
And there is an easy workaround, that object storing an exception can have a custom #inspect and something like:
```
#<ExceptionWrapper:0x00007f15aeb4ba48 for NameError with message:
undefined local variable or method `exampl' for #<Foo:0x00007f15aeb4ba48 ...>
@exception = begin; exampl; rescue Exception; $!; end
^^^^^^
Did you mean? example>
```
That's readable.
There might also be the need to disable did_you_mean and error_highlight for a given exception, I think that's a reasonable request, but also a different feature.
Maybe having something like `Exception#original_message` seems a simple way to do that (the message, unaffected by did_you_mean/error_highlight/etc).
Or have Exception#message assemble different parts of the exception, and did_you_mean/error_highlight would use a proper hook to add extra data. Then Exception#message could accept some argument whether you want the extra data or not, or just a single line, etc.
----------------------------------------
Bug #18170: Exception#inspect should not include newlines
https://bugs.ruby-lang.org/issues/18170#change-94551
* 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>