From e0273d660c361aba33c49388f4e8602112835109 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 27 Dec 2018 15:47:29 -0700 Subject: [PATCH] Display cause of errors --- src/spectator.cr | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/spectator.cr b/src/spectator.cr index 19538fe..10d426e 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -93,7 +93,7 @@ module Spectator # But if an exception occurs outside an example, # it's likely the fault of the test framework (Spectator). # So we display a helpful error that could be reported and return non-zero. - display_error(ex) + display_error_stack(ex) exit(1) end @@ -129,11 +129,25 @@ module Spectator CommandLineArgumentsConfigSource.new.apply_to(@@config_builder) end - # Displays an error message. - private def self.display_error(error) : Nil + # Displays a complete error stack. + # Prints an error and everything that caused it. + # Stacktrace is included. + private def self.display_error_stack(error) : Nil puts 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") end end