From 297dae861ac5c89c676027cdf66b015f25067d73 Mon Sep 17 00:00:00 2001 From: Roger Vuistiner Date: Thu, 17 Aug 2023 18:00:07 +0200 Subject: [PATCH] Improve default exception handler to support aggregated canceling. --- src/System.CommandLine/Invocation/InvocationPipeline.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/System.CommandLine/Invocation/InvocationPipeline.cs b/src/System.CommandLine/Invocation/InvocationPipeline.cs index 6727a927b8..4ef969781d 100644 --- a/src/System.CommandLine/Invocation/InvocationPipeline.cs +++ b/src/System.CommandLine/Invocation/InvocationPipeline.cs @@ -126,6 +126,10 @@ internal static int Invoke(ParseResult parseResult) private static int DefaultExceptionHandler(Exception exception, CliConfiguration config) { + if (exception is AggregateException aggregateException && aggregateException.InnerExceptions.Count == 1) + { + exception = aggregateException.InnerExceptions[0]; + } if (exception is not OperationCanceledException) { ConsoleHelpers.ResetTerminalForegroundColor();