aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/irb.rb9
-rw-r--r--test/irb/test_raise_exception.rb (renamed from test/irb/test_raise_no_backtrace_exception.rb)25
2 files changed, 31 insertions, 3 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 655abaf069..7547654257 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -743,7 +743,14 @@ module IRB
message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
puts message
end
- print "Maybe IRB bug!\n" if irb_bug
+ puts 'Maybe IRB bug!' if irb_bug
+ rescue Exception => handler_exc
+ begin
+ puts exc.inspect
+ puts "backtraces are hidden because #{handler_exc} was raised when processing them"
+ rescue Exception
+ puts 'Uninspectable exception occurred'
+ end
end
# Evaluates the given block using the given +path+ as the Context#irb_path
diff --git a/test/irb/test_raise_no_backtrace_exception.rb b/test/irb/test_raise_exception.rb
index 929577ad8e..9ca534dba1 100644
--- a/test/irb/test_raise_no_backtrace_exception.rb
+++ b/test/irb/test_raise_exception.rb
@@ -4,8 +4,8 @@ require "tmpdir"
require_relative "helper"
module TestIRB
- class RaiseNoBacktraceExceptionTest < TestCase
- def test_raise_exception
+ class RaiseExceptionTest < TestCase
+ def test_raise_exception_with_nil_backtrace
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /Exception: foo/, [])
e = Exception.new("foo")
@@ -15,6 +15,27 @@ module TestIRB
IRB
end
+ def test_raise_exception_with_message_exception
+ bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
+ expected = /#<Exception: foo>\nbacktraces are hidden because bar was raised when processing them/
+ assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, [])
+ e = Exception.new("foo")
+ def e.message; raise 'bar'; end
+ raise e
+IRB
+ end
+
+ def test_raise_exception_with_message_inspect_exception
+ bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
+ expected = /Uninspectable exception occurred/
+ assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, [])
+ e = Exception.new("foo")
+ def e.message; raise; end
+ def e.inspect; raise; end
+ raise e
+IRB
+ end
+
def test_raise_exception_with_invalid_byte_sequence
pend if RUBY_ENGINE == 'truffleruby' || /mswin|mingw/ =~ RUBY_PLATFORM
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []