Created
February 20, 2013 20:23
-
-
Save headius/4999244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment