[ruby-core:90659] [Ruby trunk Bug#15448] Kernel#raise should not write "cause" attribute destructively

From: mame@...
Date: 2018-12-21 12:23:35 UTC
List: ruby-core #90659
Issue #15448 has been reported by mame (Yusuke Endoh).

----------------------------------------
Bug #15448: Kernel#raise should not write "cause" attribute destructively
https://bugs.ruby-lang.org/issues/15448

* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
```
$ ./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
```



-- 
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>

In This Thread

Prev Next