diff --git a/src/ServiceBusToolset.CLI/CommandExecutionService.cs b/src/ServiceBusToolset.CLI/CommandExecutionService.cs index 1f3a4bc..131bcfe 100644 --- a/src/ServiceBusToolset.CLI/CommandExecutionService.cs +++ b/src/ServiceBusToolset.CLI/CommandExecutionService.cs @@ -36,8 +36,14 @@ await result .WithCommandAsync(cmd => HandleCommandAsync(cmd, stoppingToken)) .WithNotParsedAsync(HandleParseErrors); } - catch (Exception) + catch (Exception ex) { + Console.ResetColor(); + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(); + Console.Error.WriteLine($"Unhandled error: {ex.GetType().Name}: {ex.Message}"); + Console.Error.WriteLine(ex.ToString()); + Console.ResetColor(); Environment.ExitCode = 1; } finally diff --git a/src/ServiceBusToolset.CLI/Common/Commands/BaseCommandHandler{TCommand,TResult}.cs b/src/ServiceBusToolset.CLI/Common/Commands/BaseCommandHandler{TCommand,TResult}.cs index 4be0d85..ba42e54 100644 --- a/src/ServiceBusToolset.CLI/Common/Commands/BaseCommandHandler{TCommand,TResult}.cs +++ b/src/ServiceBusToolset.CLI/Common/Commands/BaseCommandHandler{TCommand,TResult}.cs @@ -43,6 +43,12 @@ public async Task ExecuteAsync(TCommand command, Output.Warning("\nOperation cancelled."); return 1; } + catch (Exception ex) + { + Output.Error($"Unexpected error: {ex.GetType().Name}: {ex.Message}"); + Output.Verbose(ex.ToString(), verbose); + return 1; + } } protected abstract Task> ExecuteCoreAsync(TCommand command, bool verbose, CancellationToken cancellationToken = default); diff --git a/src/ServiceBusToolset.TestHarness/CommandExecutionService.cs b/src/ServiceBusToolset.TestHarness/CommandExecutionService.cs index 472ba75..abcea44 100644 --- a/src/ServiceBusToolset.TestHarness/CommandExecutionService.cs +++ b/src/ServiceBusToolset.TestHarness/CommandExecutionService.cs @@ -21,8 +21,14 @@ await result .WithCommandAsync(cmd => HandleCommandAsync(cmd, stoppingToken)) .WithNotParsedAsync(HandleParseErrors); } - catch (Exception) + catch (Exception ex) { + Console.ResetColor(); + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(); + Console.Error.WriteLine($"Unhandled error: {ex.GetType().Name}: {ex.Message}"); + Console.Error.WriteLine(ex.ToString()); + Console.ResetColor(); Environment.ExitCode = 1; } finally diff --git a/src/ServiceBusToolset.TestHarness/Common/Commands/BaseCommandHandler.cs b/src/ServiceBusToolset.TestHarness/Common/Commands/BaseCommandHandler.cs index 2ccd244..1179970 100644 --- a/src/ServiceBusToolset.TestHarness/Common/Commands/BaseCommandHandler.cs +++ b/src/ServiceBusToolset.TestHarness/Common/Commands/BaseCommandHandler.cs @@ -41,6 +41,12 @@ public async Task ExecuteAsync(TCommand command, Output.Warning("\nOperation cancelled."); return 1; } + catch (Exception ex) + { + Output.Error($"Unexpected error: {ex.GetType().Name}: {ex.Message}"); + Output.Verbose(ex.ToString(), verbose); + return 1; + } } protected abstract Task ExecuteCoreAsync(TCommand command, bool verbose, CancellationToken cancellationToken = default);