From f741fd2d9d55afb535c3fd5635b2ee5252bedb68 Mon Sep 17 00:00:00 2001 From: hsbt Date: Wed, 13 Aug 2014 02:19:48 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/irb.rb | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'lib/irb.rb') 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 -- cgit v1.2.3