Bug #17033
closedInfinite Traceback when encountering an Exception while catching an Exception
Description
In Ruby 2.7.1 when an Exception occurs and another occurs when handling the first one it results in an infinite Traceback that doesn't mention the error.
class MyException < StandardError
def initialize(obj)
@obj = obj
end
def to_s
@obj.to_strm
end
end
begin
raise MyException.new('test'), 'message'
rescue StandardError => e
puts e.to_s
end
In the above instance, there's a typo to_strm
doesn't exist for type String, but instead of a normal case of a typo saying that the method doesn't exist the output is
~ λ ruby ruby_traceback_hell.rb
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
...
it keeps going without printing any sort of message about the actual error.
It's expected that this would result in a message saying that the method is undefined, and this is the behavior on 2.5.1, and appears to be a regression in 2.7.1
Updated by NickHackman (Nick Hackman) over 4 years ago
NickHackman (Nick Hackman) wrote:
In Ruby 2.7.1 when an Exception occurs and another occurs when handling the first one it results in an infinite Traceback that doesn't mention the error.
class MyException < StandardError def initialize(obj) @obj = obj end def to_s @obj.to_strm end end begin raise MyException.new('test'), 'message' rescue StandardError => e puts e.to_s end
In the above instance, there's a typo
to_strm
doesn't exist for type String, but instead of a normal case of a typo saying that the method doesn't exist the output is~ λ ruby ruby_traceback_hell.rb Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): ...
it keeps going without printing any sort of message about the actual error.
It's expected that this would result in a message saying that the method is undefined, and this is the behavior on 2.5.1, and appears to be a regression in 2.7.1
If this is an actual issue is it possible I could work on it?
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
- Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN to 2.5: DONTNEED, 2.6: REQUIRED, 2.7: REQUIRED
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
- Status changed from Open to Closed
Applied in changeset git|579645d9f870fa4116dcd3200bbbb6e2c0b7f400.
Fixed infinite loop at error in printing cause [Bug #17033]
Updated by ujihisa (Tatsuhiro Ujihisa) over 4 years ago
(Oh I see, this and https://bugs.ruby-lang.org/issues/14566#change-71448 were independent)
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
Yes, it is similar however occurs while printing causes, which was added at 2.6.
Updated by nagachika (Tomoyuki Chikanaga) over 4 years ago
- Backport changed from 2.5: DONTNEED, 2.6: REQUIRED, 2.7: REQUIRED to 2.5: DONTNEED, 2.6: REQUIRED, 2.7: DONE
ruby_2_7 27fa1c61b78c1685ccf9ac203a95cfa9041d618f merged revision(s) 579645d9f870fa4116dcd3200bbbb6e2c0b7f400.
Updated by usa (Usaku NAKAMURA) over 3 years ago
- Backport changed from 2.5: DONTNEED, 2.6: REQUIRED, 2.7: DONE to 2.5: DONTNEED, 2.6: DONE, 2.7: DONE
backported into ruby_2_6 at r67913.