secret
Created

  • Download Gist
log_1.6_error.rb
Ruby
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 37
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.