Project

General

Profile

Actions

Feature #14685

open

IRB doesn't print exception cause

Added by RubyBugs (A Nonymous) over 6 years ago. Updated over 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:86529]

Description

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:

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:

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?

Updated by RubyBugs (A Nonymous) over 6 years ago

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

Updated by Hanmac (Hans Mackowiak) over 6 years ago

i tested it with multiple ruby versions, both irb and ruby, because i wanted to see what happen

irb doesn't print the cause, but ruby itself doesn't do too.

should that be done in ruby itself too?
(and maybe a way to disable that?)

Actions #3

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Tracker changed from Bug to Feature
  • ruby -v deleted (ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin15)
  • Backport deleted (2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN)

Updated by RubyBugs (A Nonymous) over 6 years ago

May I ask: a very quick path to solving this would be for me (or someone else) to turn my workaround monkey-patch of IRB (see comment #1 above) into a pull request to IRB in the standard library.

Ruby maintainers: are you interested in receiving such a PR? We can take that on if there is interest in reviewing it.

Updated by RubyBugs (A Nonymous) over 6 years ago

Note that per @Hanmac (Hans Mackowiak) above in comment #2, separate work might be necessary to also print the #cause in default Ruby uncaught exception print out. But that is not the subject of this issue.

Hanmac -- should I open a separate issue to cover the printing of #cause in Ruby uncaught exceptions, as a separate issue from IRB?

RubyBugs (A Nonymous) wrote:

May I ask: a very quick path to solving this would be for me (or someone else) to turn my workaround monkey-patch of IRB (see comment #1 above) into a pull request to IRB in the standard library.

Ruby maintainers: are you interested in receiving such a PR? We can take that on if there is interest in reviewing it.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0