Skip to content

Instantly share code, notes, and snippets.

@headius
Created February 20, 2013 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save headius/4999244 to your computer and use it in GitHub Desktop.
Save headius/4999244 to your computer and use it in GitHub Desktop.
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