< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #14685 has been updated by RubyBugs (A Nonymous).
For Ruby 2.3.4, here is a working monkey-patch which causes IRB to behave as expected above:
https://gist.github.com/ms-ati/c11658166c8844dfa6b1caed480d02b3
----------------------------------------
Bug #14685: IRB doesn't print exception cause
https://bugs.ruby-lang.org/issues/14685#change-71470
* Author: RubyBugs (A Nonymous)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin15
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
# Summary
IRB doesn't print `Exception#cause`.
Because IRB also doesn't offer access to raised exceptions (see https://bugs.ruby-lang.org/issues/14684), in effect this make the `#cause` of exceptions inaccessible without extra work and tooling at the console
## Details
Consider the following IRB session:
~~~ ruby
def method_raises_exception_with_cause
1/0
rescue StandardError => e
raise "An exception with a cause"
end
method_raises_exception_with_cause
#RuntimeError: An exception with a cause
# from (irb):4:in `rescue in method_raises_exception_with_cause'
# from (irb):2:in `method_raises_exception_with_cause'
# from (irb):7
# from /Users/marcsiegel/.rubies/ruby-2.3.4/bin/irb:11:in `<main>'
~~~
### Expected
In order to work with the `#cause` feature in recent Rubies, which is generally accepted Ruby practice today, we expect to see the `#cause` printed at the console. In fact, we would expect it to be recursively printed if there were a series of linked causes. For example:
~~~ ruby
method_raises_exception_with_cause
# One could imagine seeing printed from IRB:
#RuntimeError: An exception with a cause
# from (irb):4:in `rescue in method_raises_exception_with_cause'
# from (irb):2:in `method_raises_exception_with_cause'
# from (irb):7
# from /Users/marcsiegel/.rubies/ruby-2.3.4/bin/irb:11:in `<main>'
#Caused by: ZeroDivisionError: divided by 0
# from (irb):3:in `/'
# from (irb):2:in `method_raises_exception_with_cause'
# from (irb):7
# from /Users/marcsiegel/.rubies/ruby-2.3.4/bin/irb:11:in `<main>'
~~~
### Discussion
Ruby nested exceptions via `#cause` are a stable and accepted part of the Ruby landscape. All major Ruby tooling we are aware of, including production services such as BugSnag and AirBrake, as well as IDEs such as RubyMine, support the `#cause` mechanism for conveying nested exception contexts.
It is surprising that IRB does not. Would this be a big challenge to change?
--
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>