Project

General

Profile

Bug #15448

Kernel#raise should not write "cause" attribute destructively

Added by mame (Yusuke Endoh) 7 months ago. Updated 5 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:90659]

Description

$ ./miniruby -e '
begin
  raise "foo"
rescue => e1
  begin
    raise "bar"
  rescue => e2
    raise e1, cause: e2
  end
end
'
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
...

This is caused by circular "cause" chain:

begin
  raise "foo"
rescue => e1
  begin
    raise "bar"
  rescue => e2
    begin
      # Virtually `e1.cause = e2` which makes the cause chain circular
      raise e1, cause: e2
    rescue
      p $!                   #=> #<RuntimeError: foo>
      p $!.cause             #=> #<RuntimeError: bar>
      p $!.cause.cause       #=> #<RuntimeError: foo>
      p $!.cause.cause.cause #=> #<RuntimeError: bar>
      p $!.cause.cause.object_id == $!.object_id
    end
  end
end

Associated revisions

Revision 66493
Added by nobu (Nobuyoshi Nakada) 7 months ago

Fix for circular causes

  • eval_error.c (show_cause): get rid of infinite recursion on circular causes. [Bug #15447]

Revision 66510
Added by nobu (Nobuyoshi Nakada) 7 months ago

Prohibit circular causes [Bug #15447]

History

#1

Updated by nobu (Nobuyoshi Nakada) 5 months ago

  • Description updated (diff)
#2

Updated by nobu (Nobuyoshi Nakada) 5 months ago

  • Status changed from Open to Closed

Also available in: Atom PDF