summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorsorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-23 18:17:39 +0000
committersorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-23 18:17:39 +0000
commitdaaebaec79f60796b9c864907ad03d1e02b93fb2 (patch)
treeee5766787fd1c104252c07c0611a55c1f47cc249 /lib
parent953385c6bc1a6fed1c4198d323e2b523b18c9052 (diff)
Print backtrace in reverse order on IRB too
[Feature #8861] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/irb.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 3a5fdbc698..31190ba649 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -497,7 +497,6 @@ module IRB
rescue Exception => exc
end
if exc
- print exc.class, ": ", exc, "\n"
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
!(SyntaxError === exc)
irb_bug = true
@@ -509,26 +508,32 @@ module IRB
lasts = []
levels = 0
if exc.backtrace
- for m in exc.backtrace
+ filtered_line_count = 0
+ exc.backtrace.each_with_index do |m, i|
+ num_str = (i + 1 - filtered_line_count).to_s.rjust(9, ' ')
m = @context.workspace.filter_backtrace(m) unless irb_bug
if m
if messages.size < @context.back_trace_limit
- messages.push "\tfrom "+m
+ messages.push "#{num_str}: from "+m
else
- lasts.push "\tfrom "+m
+ lasts.push "#{num_str}: from "+m
if lasts.size > @context.back_trace_limit
lasts.shift
levels += 1
end
end
+ else
+ filtered_line_count += 1
end
end
end
- print messages.join("\n"), "\n"
+ print "Traceback (most recent call last):\n"
unless lasts.empty?
+ print lasts.reverse.join("\n"), "\n"
printf "... %d levels...\n", levels if levels > 0
- print lasts.join("\n"), "\n"
end
+ print messages.reverse.join("\n"), "\n"
+ print exc.class, ": ", exc, "\n"
print "Maybe IRB bug!\n" if irb_bug
end
end