summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--lib/irb.rb24
-rw-r--r--test/irb/test_raise_no_backtrace_exception.rb14
3 files changed, 34 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 07858c03d3..e39631a82c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Aug 13 11:17:00 2014 Shimpei Makimoto <github@makimoto.org>
+
+ * lib/irb.rb: Prevent irb from crashing when exception with
+ nil backtrace is raised.
+ [fix GH-434][ruby-core:58078][Bug #9063]
+ * test/irb/test_raise_no_backtrace_exception.rb: ditto.
+
Wed Aug 13 11:08:55 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* lib/irb/completion.rb: fixed broken completion list with
diff --git a/lib/irb.rb b/lib/irb.rb
index 9bd37c8b0b..1bbb6eceb8 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -497,7 +497,7 @@ module IRB
end
if exc
print exc.class, ": ", exc, "\n"
- if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
+ if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
!(SyntaxError === exc)
irb_bug = true
else
@@ -507,16 +507,18 @@ module IRB
messages = []
lasts = []
levels = 0
- for m in exc.backtrace
- m = @context.workspace.filter_backtrace(m) unless irb_bug
- if m
- if messages.size < @context.back_trace_limit
- messages.push "\tfrom "+m
- else
- lasts.push "\tfrom "+m
- if lasts.size > @context.back_trace_limit
- lasts.shift
- levels += 1
+ if exc.backtrace
+ for m in exc.backtrace
+ m = @context.workspace.filter_backtrace(m) unless irb_bug
+ if m
+ if messages.size < @context.back_trace_limit
+ messages.push "\tfrom "+m
+ else
+ lasts.push "\tfrom "+m
+ if lasts.size > @context.back_trace_limit
+ lasts.shift
+ levels += 1
+ end
end
end
end
diff --git a/test/irb/test_raise_no_backtrace_exception.rb b/test/irb/test_raise_no_backtrace_exception.rb
new file mode 100644
index 0000000000..e8204d7a1b
--- /dev/null
+++ b/test/irb/test_raise_no_backtrace_exception.rb
@@ -0,0 +1,14 @@
+require 'test/unit'
+require_relative '../ruby/envutil'
+
+module TestIRB
+ class TestRaiseNoBacktraceException < Test::Unit::TestCase
+ def test_raise_exception
+ status = assert_in_out_err(%w[-rirb -e IRB.start(__FILE__) -- -f --], <<-IRB, /Exception: foo/, [])
+ e = Exception.new("foo")
+ def e.backtrace; nil; end
+ raise e
+IRB
+ end
+ end
+end