From fccd55ed0a22e635366ea230b4786e05f68d18df Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 29 May 2021 17:33:45 -0600 Subject: [PATCH] Improve appearance of multi-line error messages --- .../formatting/components/error_result_block.cr | 11 +++++++++-- .../formatting/components/fail_result_block.cr | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/spectator/formatting/components/error_result_block.cr b/src/spectator/formatting/components/error_result_block.cr index 10d9826..6ebbab5 100644 --- a/src/spectator/formatting/components/error_result_block.cr +++ b/src/spectator/formatting/components/error_result_block.cr @@ -10,7 +10,7 @@ module Spectator::Formatting::Components end private def subtitle - @result.error.message + @result.error.message.try(&.each_line.first) end private def subtitle_label @@ -19,10 +19,17 @@ module Spectator::Formatting::Components private def content(io) error = @result.error + lines = error.message.try(&.lines) || {"".colorize(:purple)} line(io) do io << "#{error.class}: ".colorize(:red) - io << error.message + io << lines.first + end + + lines.skip(1).each do |entry| + line(io) do + io << entry + end end error.backtrace?.try do |backtrace| diff --git a/src/spectator/formatting/components/fail_result_block.cr b/src/spectator/formatting/components/fail_result_block.cr index 9b20a1b..1b22c6a 100644 --- a/src/spectator/formatting/components/fail_result_block.cr +++ b/src/spectator/formatting/components/fail_result_block.cr @@ -10,7 +10,7 @@ module Spectator::Formatting::Components end private def subtitle - @result.error.message + @result.error.message.try(&.each_line.first) end private def subtitle_label