Improve internal error handling output

This commit is contained in:
Michael Miller 2020-09-26 22:25:53 -06:00
parent 543df88d39
commit d663e82c36
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436

View file

@ -103,7 +103,7 @@ module Spectator
# But if an exception occurs outside an example, # But if an exception occurs outside an example,
# it's likely the fault of the test framework (Spectator). # it's likely the fault of the test framework (Spectator).
# So we display a helpful error that could be reported and return non-zero. # So we display a helpful error that could be reported and return non-zero.
display_error_stack(ex) display_framework_error(ex)
false false
end end
@ -147,22 +147,11 @@ module Spectator
# Displays a complete error stack. # Displays a complete error stack.
# Prints an error and everything that caused it. # Prints an error and everything that caused it.
# Stacktrace is included. # Stacktrace is included.
private def display_error_stack(error) : Nil private def display_framework_error(error) : Nil
puts STDERR.puts
puts "Encountered an unexpected error in framework" STDERR.puts "!> Spectator encountered an unexpected error."
# Loop while there's a cause for the error. STDERR.puts "!> This is probably a bug and should be reported."
# Print each error in the stack. STDERR.puts
loop do error.inspect_with_backtrace(STDERR)
display_error(error)
error = error.cause
break unless error
end
end
# Display a single error and its stacktrace.
private def display_error(error) : Nil
puts
puts "Caused by: #{error.message}"
puts error.backtrace.join("\n")
end end
end end