зеркало из https://github.com/github/ruby.git
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:
Родитель
953385c6bc
Коммит
daaebaec79
1
NEWS
1
NEWS
|
@ -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]
|
||||
|
|
17
lib/irb.rb
17
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче