Project

General

Profile

Actions

Feature #14684

closed

IRB swallows exceptions

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

Status:
Closed
Target version:
-
[ruby-core:86528]

Description

Summary

IRB swallows exceptions, doesn't provide programatic access to raised exception in session.

Details

On Ruby 2.3.4, we find it surprising that exceptions in IRB are swallowed, and are not accessible at the two locations we checked:

  1. In the global variable for most recent exception $!
  2. In the return value of evaluating the expression _

Consider this IRB session:

def method_which_raises
  1/0
end

method_which_raises

# ZeroDivisionError: divided by 0
#	from (irb):10:in `/'
#	from (irb):10:in `method_which_raises'
#	from (irb):13
#	from /Users/marcsiegel/.rubies/ruby-2.3.4/bin/irb:11:in `<main>'

Observed

Neither _ nor $! give access to the raised exception, so that during development or debugging, one could dig further into what had occurred.

Expected

Either _ or $! would give programmatic access in IRB to an exception

Updated by hsbt (Hiroshi SHIBATA) almost 6 years ago

  • Status changed from Open to Assigned
  • Assignee set to keiju (Keiju Ishitsuka)

Updated by nobu (Nobuyoshi Nakada) almost 6 years ago

$! isn't accessible outside rescue clause, even without irb.

Actions #3

Updated by nobu (Nobuyoshi Nakada) almost 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) almost 6 years ago

nobu (Nobuyoshi Nakada) wrote:

$! isn't accessible outside rescue clause, even without irb.

In IRB, should $! be set, or a proxy for it be set, when the IRB eval handles an exception?

Actions #5

Updated by nobu (Nobuyoshi Nakada) almost 6 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r63150.


irb.rb: restore the last error

  • lib/irb.rb (eval_input): restore the last error $!, as the
    previous result. [Feature #14684]

  • lib/irb/context.rb (evaluate): add exception keyword argument
    to set the last error.

Updated by RubyBugs (A Nonymous) almost 6 years ago

@nobu (Nobuyoshi Nakada):

Would it be possible to back-port this to Ruby 2.3, 2.4, and 2.5?

Or, would you be willing to review patches from me to back-port this?

Updated by nobu (Nobuyoshi Nakada) almost 6 years ago

I changed the tracker to "Feature", as I thought it would not need to backport.
But branch maintainers may have different opinion.
It seems easy to apply the commits to the old branches.

Updated by RubyBugs (A Nonymous) almost 6 years ago

Hmm. Our hope would be to have this "easy" change back-ported to 2.3, 2.4, and 2.5 -- waiting until December to have it in final 2.6 seems a long time to wait for this? Please let us know how we can help.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0