mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
irb.rb: hoist out handle_exception
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
081df64083
commit
fb68dfc40e
1 changed files with 38 additions and 34 deletions
72
lib/irb.rb
72
lib/irb.rb
|
@ -497,45 +497,49 @@ module IRB
|
||||||
rescue Exception => exc
|
rescue Exception => exc
|
||||||
end
|
end
|
||||||
if exc
|
if exc
|
||||||
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
|
handle_exception(exc)
|
||||||
!(SyntaxError === exc)
|
|
||||||
irb_bug = true
|
|
||||||
else
|
|
||||||
irb_bug = false
|
|
||||||
end
|
|
||||||
|
|
||||||
messages = []
|
|
||||||
lasts = []
|
|
||||||
levels = 0
|
|
||||||
if exc.backtrace
|
|
||||||
count = 0
|
|
||||||
exc.backtrace.each do |m|
|
|
||||||
m = @context.workspace.filter_backtrace(m) or next unless irb_bug
|
|
||||||
m = sprintf("%9d: from %s", (count += 1), m)
|
|
||||||
if messages.size < @context.back_trace_limit
|
|
||||||
messages.push(m)
|
|
||||||
elsif lasts.size < @context.back_trace_limit
|
|
||||||
lasts.push(m).shift
|
|
||||||
levels += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
attr = STDOUT.tty? ? ATTR_TTY : ATTR_PLAIN
|
|
||||||
print "#{attr[1]}Traceback#{attr[]} (most recent call last):\n"
|
|
||||||
unless lasts.empty?
|
|
||||||
puts lasts.reverse
|
|
||||||
printf "... %d levels...\n", levels if levels > 0
|
|
||||||
end
|
|
||||||
puts messages.reverse
|
|
||||||
messages = exc.to_s.split(/\n/)
|
|
||||||
print "#{attr[1]}#{exc.class} (#{attr[4]}#{messages.shift}#{attr[0, 1]})#{attr[]}\n"
|
|
||||||
puts messages.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
|
|
||||||
print "Maybe IRB bug!\n" if irb_bug
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_exception(exc)
|
||||||
|
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
|
||||||
|
!(SyntaxError === exc)
|
||||||
|
irb_bug = true
|
||||||
|
else
|
||||||
|
irb_bug = false
|
||||||
|
end
|
||||||
|
|
||||||
|
messages = []
|
||||||
|
lasts = []
|
||||||
|
levels = 0
|
||||||
|
if exc.backtrace
|
||||||
|
count = 0
|
||||||
|
exc.backtrace.each do |m|
|
||||||
|
m = @context.workspace.filter_backtrace(m) or next unless irb_bug
|
||||||
|
m = sprintf("%9d: from %s", (count += 1), m)
|
||||||
|
if messages.size < @context.back_trace_limit
|
||||||
|
messages.push(m)
|
||||||
|
elsif lasts.size < @context.back_trace_limit
|
||||||
|
lasts.push(m).shift
|
||||||
|
levels += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
attr = STDOUT.tty? ? ATTR_TTY : ATTR_PLAIN
|
||||||
|
print "#{attr[1]}Traceback#{attr[]} (most recent call last):\n"
|
||||||
|
unless lasts.empty?
|
||||||
|
puts lasts.reverse
|
||||||
|
printf "... %d levels...\n", levels if levels > 0
|
||||||
|
end
|
||||||
|
puts messages.reverse
|
||||||
|
messages = exc.to_s.split(/\n/)
|
||||||
|
print "#{attr[1]}#{exc.class} (#{attr[4]}#{messages.shift}#{attr[0, 1]})#{attr[]}\n"
|
||||||
|
puts messages.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
|
||||||
|
print "Maybe IRB bug!\n" if irb_bug
|
||||||
|
end
|
||||||
|
|
||||||
# Evaluates the given block using the given +path+ as the Context#irb_path
|
# Evaluates the given block using the given +path+ as the Context#irb_path
|
||||||
# and +name+ as the Context#irb_name.
|
# and +name+ as the Context#irb_name.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue