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
This commit is contained in:
sorah 2017-12-23 18:17:39 +00:00
parent 953385c6bc
commit daaebaec79
2 changed files with 12 additions and 6 deletions

1
NEWS
View File

@ -276,6 +276,7 @@ with all sufficient information, see the ChangeLog file or Redmine
* IRB * IRB
* Print backtrace and error message in reverse order [Feature #8661] [experimental]
* `binding.irb` automatically requires irb and runs [Bug #13099] [experimental] * `binding.irb` automatically requires irb and runs [Bug #13099] [experimental]
* `binding.irb` on its start shows source around the line where it was called * `binding.irb` on its start shows source around the line where it was called
[Feature #14124] [Feature #14124]

View File

@ -497,7 +497,6 @@ module IRB
rescue Exception => exc rescue Exception => exc
end end
if exc if exc
print exc.class, ": ", exc, "\n"
if exc.backtrace && 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) !(SyntaxError === exc)
irb_bug = true irb_bug = true
@ -509,26 +508,32 @@ module IRB
lasts = [] lasts = []
levels = 0 levels = 0
if exc.backtrace 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 m = @context.workspace.filter_backtrace(m) unless irb_bug
if m if m
if messages.size < @context.back_trace_limit if messages.size < @context.back_trace_limit
messages.push "\tfrom "+m messages.push "#{num_str}: from "+m
else else
lasts.push "\tfrom "+m lasts.push "#{num_str}: from "+m
if lasts.size > @context.back_trace_limit if lasts.size > @context.back_trace_limit
lasts.shift lasts.shift
levels += 1 levels += 1
end end
end end
else
filtered_line_count += 1
end end
end end
end end
print messages.join("\n"), "\n" print "Traceback (most recent call last):\n"
unless lasts.empty? unless lasts.empty?
print lasts.reverse.join("\n"), "\n"
printf "... %d levels...\n", levels if levels > 0 printf "... %d levels...\n", levels if levels > 0
print lasts.join("\n"), "\n"
end end
print messages.reverse.join("\n"), "\n"
print exc.class, ": ", exc, "\n"
print "Maybe IRB bug!\n" if irb_bug print "Maybe IRB bug!\n" if irb_bug
end end
end end