From 01f707c78dca7e5b7f4cb7a623851a61b6053032 Mon Sep 17 00:00:00 2001 From: Phil Scott Date: Fri, 23 Apr 2021 09:48:19 -0400 Subject: [PATCH] Exposes Pretty property of CommandAppException If a user is propagating the exceptions we aren't going to automatically display them. They might still want to get this exception message and use it, so we'll make it publicly available. --- src/Spectre.Console.Testing/Cli/CommandAppTester.cs | 9 +++++++++ src/Spectre.Console/Cli/CommandAppException.cs | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Spectre.Console.Testing/Cli/CommandAppTester.cs b/src/Spectre.Console.Testing/Cli/CommandAppTester.cs index 00d5080..4ad0276 100644 --- a/src/Spectre.Console.Testing/Cli/CommandAppTester.cs +++ b/src/Spectre.Console.Testing/Cli/CommandAppTester.cs @@ -53,6 +53,15 @@ namespace Spectre.Console.Testing } catch (T ex) { + if (ex is CommandAppException commandAppException && commandAppException.Pretty != null) + { + console.Write(commandAppException.Pretty); + } + else + { + console.WriteLine(ex.Message); + } + return new CommandAppFailure(ex, console.Output); } catch (Exception ex) diff --git a/src/Spectre.Console/Cli/CommandAppException.cs b/src/Spectre.Console/Cli/CommandAppException.cs index a1fd8df..7d0ef6f 100644 --- a/src/Spectre.Console/Cli/CommandAppException.cs +++ b/src/Spectre.Console/Cli/CommandAppException.cs @@ -8,7 +8,10 @@ namespace Spectre.Console.Cli /// public abstract class CommandAppException : Exception { - internal IRenderable? Pretty { get; } + /// + /// Gets the pretty formatted exception message. + /// + public IRenderable? Pretty { get; } internal virtual bool AlwaysPropagateWhenDebugging => false;