Display cause of errors
This commit is contained in:
parent
c0be260f98
commit
e0273d660c
|
@ -93,7 +93,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(ex)
|
display_error_stack(ex)
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -129,11 +129,25 @@ module Spectator
|
||||||
CommandLineArgumentsConfigSource.new.apply_to(@@config_builder)
|
CommandLineArgumentsConfigSource.new.apply_to(@@config_builder)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Displays an error message.
|
# Displays a complete error stack.
|
||||||
private def self.display_error(error) : Nil
|
# Prints an error and everything that caused it.
|
||||||
|
# Stacktrace is included.
|
||||||
|
private def self.display_error_stack(error) : Nil
|
||||||
puts
|
puts
|
||||||
puts "Encountered an unexpected error in framework"
|
puts "Encountered an unexpected error in framework"
|
||||||
puts error.message
|
# Loop while there's a cause for the error.
|
||||||
|
# Print each error in the stack.
|
||||||
|
loop do
|
||||||
|
display_error(error)
|
||||||
|
error = error.cause
|
||||||
|
break unless error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Display a single error and its stacktrace.
|
||||||
|
private def self.display_error(error) : Nil
|
||||||
|
puts
|
||||||
|
puts "Caused by: #{error.message}"
|
||||||
puts error.backtrace.join("\n")
|
puts error.backtrace.join("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue