public
Last active

  • Download Gist
gistfile1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
def expression_backtrace(backtrace)
new_trace = []
backtrace.each do |line|
match = /(.*):([0-9]+):in/.match line
file, linenum = match[1], match[2].to_i
 
new_trace << line
 
if File.exist?(file)
expr = File.readlines(file)[linenum - 1]
expr.strip!
 
new_trace << "\tat expression: \"#{expr}\""
end
end
 
new_trace
end
 
def foo
raise # raise an error
end
 
def bar
foo # call foo in bar
end
 
def baz
bar # call bar in baz
end
 
begin
baz
rescue => e
puts expression_backtrace(e.backtrace)
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.