-
-
Save retoo/89e907998765d6d60f63 to your computer and use it in GitHub Desktop.
This file contains 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
# 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