ruby-changes:49314
From: sorah <ko1@a...>
Date: Sun, 24 Dec 2017 03:17:45 +0900 (JST)
Subject: [ruby-changes:49314] sorah:r61431 (trunk): Print backtrace in reverse order on IRB too
sorah 2017-12-24 03:17:39 +0900 (Sun, 24 Dec 2017) New Revision: 61431 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61431 Log: Print backtrace in reverse order on IRB too [Feature #8861] Modified files: trunk/NEWS trunk/lib/irb.rb Index: lib/irb.rb =================================================================== --- lib/irb.rb (revision 61430) +++ lib/irb.rb (revision 61431) @@ -497,7 +497,6 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L497 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 https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L508 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 Index: NEWS =================================================================== --- NEWS (revision 61430) +++ NEWS (revision 61431) @@ -276,6 +276,7 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L276 * 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] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/