Create a gist now

Instantly share code, notes, and snippets.

@retoo /log_1.6_error.rb Secret
Created Feb 15, 2013

# 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