diff options
author | sorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-23 18:17:39 +0000 |
---|---|---|
committer | sorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-23 18:17:39 +0000 |
commit | daaebaec79f60796b9c864907ad03d1e02b93fb2 (patch) | |
tree | ee5766787fd1c104252c07c0611a55c1f47cc249 | |
parent | 953385c6bc1a6fed1c4198d323e2b523b18c9052 (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
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | lib/irb.rb | 17 |
2 files changed, 12 insertions, 6 deletions
@@ -276,6 +276,7 @@ with all sufficient information, see the ChangeLog file or Redmine * IRB + * Print backtrace and error message in reverse order [Feature #8661] [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 [Feature #14124] 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 |