From d97a3ee68b98239d57853b6a808e6b9ee9f4b35a Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Thu, 30 May 2024 16:19:35 +0200 Subject: [PATCH] Check for errors while saving --- .../Commands/GenerateCommand.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/OpenApi.Client.Cli/Commands/GenerateCommand.cs b/src/OpenApi.Client.Cli/Commands/GenerateCommand.cs index 7e271b6..dadc5d4 100644 --- a/src/OpenApi.Client.Cli/Commands/GenerateCommand.cs +++ b/src/OpenApi.Client.Cli/Commands/GenerateCommand.cs @@ -80,16 +80,25 @@ SerializationResultError serializationResultError in serializationResult.Errors AnsiConsole.MarkupLine($"[red]Error: {generatorResultError.Message}[/]"); } - return -1; + return -3; } generatedSource = generatorResult.Result; - await File.WriteAllTextAsync( - settings.Output, - generatedSource, - cancellationTokenSource.Token - ); + try + { + await File.WriteAllTextAsync( + settings.Output, + generatedSource, + cancellationTokenSource.Token + ); + } + catch (Exception e) + { + AnsiConsole.MarkupLine($"[red]Error: {e.Message}[/]"); + + return -4; + } return 0; }