From 939772ee9603277a8eb8d03dc69c13926bf027b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 4 Jan 2023 21:27:10 +0100 Subject: [PATCH] Fix: Unwrap nested errors in error handler for `Crystal::Error` (#12888) --- src/compiler/crystal/command.cr | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/compiler/crystal/command.cr b/src/compiler/crystal/command.cr index 7f9ea58148be..ca66b460d83b 100644 --- a/src/compiler/crystal/command.cr +++ b/src/compiler/crystal/command.cr @@ -141,6 +141,14 @@ class Crystal::Command rescue ex : Crystal::Error report_warnings + # This unwraps nested errors which could be caused by `require` which wraps + # errors in order to trace the require path. The causes are listed similarly + # to `#inspect_with_backtrace` but without the backtrace. + while cause = ex.cause + error ex.message, exit_code: nil + ex = cause + end + error ex.message rescue ex : OptionParser::Exception error ex.message