Skip to content

Instantly share code, notes, and snippets.

@retoo
Created February 15, 2013 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retoo/89e907998765d6d60f63 to your computer and use it in GitHub Desktop.
Save retoo/89e907998765d6d60f63 to your computer and use it in GitHub Desktop.
# original log_error method
def self.log_single_error(exception)
message = "\n#{exception.class} (#{exception.message}):\n"
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
message << " " << exception.backtrace.join("\n ")
$stderr.puts("#{message}\n\n")
end
def self.log_and_exit_if_error
begin
yield
rescue => e
print_error(e)
exit 1
end
end
def self.print_error(exception)
steps = 30
while true
log_single_error(exception)
# use begin/rescue block as respond_to is not relaible
begin
break if exception == exception.cause
exception = exception.cause
rescue
# no cause field
break
end
break unless exception
break if steps < 0
steps -= 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment