Improve error handling for dotnet pack failures
Enhanced the error message for 'dotnet pack' failures to include the exit code. Updated the resource string and its usage to provide more informative feedback. Added cleanup of the temporary directory on cancellation and improved progress bar visibility.
This commit is contained in:
+1
-1
@@ -96,7 +96,7 @@ namespace aeqw89.tools.Publish {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Failed to pack; ensure that 'dotnet build' succeeds before running this program..
|
||||
/// Looks up a localized string similar to Failed to pack with exit code '{0}'; ensure that 'dotnet build' succeeds before running this program..
|
||||
/// </summary>
|
||||
internal static string dotnet_pack_failure {
|
||||
get {
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<value>The project file '{0}' is irreparable becuase it is missing a '{1}' property, and the value cannot be guessed.</value>
|
||||
</data>
|
||||
<data name="dotnet_pack_failure" xml:space="preserve">
|
||||
<value>Failed to pack; ensure that 'dotnet build' succeeds before running this program.</value>
|
||||
<value>Failed to pack with exit code '{0}'; ensure that 'dotnet build' succeeds before running this program.</value>
|
||||
</data>
|
||||
<data name="failed_to_clean_up" xml:space="preserve">
|
||||
<value>Could not delete temporary directory '{0}' due to error '{1}'</value>
|
||||
|
||||
@@ -238,9 +238,20 @@ public static class Program {
|
||||
}
|
||||
|
||||
var outDir = Path.GetRandomFileName();
|
||||
result = AnsiConsole.Status()
|
||||
Console.CancelKeyPress += (sender, eventArgs) => {
|
||||
try {
|
||||
Directory.Delete(outDir, true);
|
||||
AnsiConsole.MarkupLine("[yellow]Cleaned up temporary directory[/]");
|
||||
}
|
||||
catch (Exception e) {
|
||||
ShowError(string.Format(Exceptions.failed_to_clean_up.EscapeMarkup(), outDir.EscapeMarkup(),
|
||||
e.ToString().EscapeMarkup()));
|
||||
}
|
||||
};
|
||||
|
||||
var exitCode = AnsiConsole.Status()
|
||||
.Spinner(Spinner.Known.Dots)
|
||||
.Start<bool>("Creating package with 'dotnet pack' ", ctx => {
|
||||
.Start<int>("Creating package with 'dotnet pack' ", ctx => {
|
||||
var p = Process.Start(new ProcessStartInfo() {
|
||||
FileName = "dotnet",
|
||||
Arguments = $"pack -o {outDir}",
|
||||
@@ -250,11 +261,11 @@ public static class Program {
|
||||
RedirectStandardError = !Verbose
|
||||
});
|
||||
p?.WaitForExit();
|
||||
return p?.ExitCode == 0;
|
||||
return p?.ExitCode ?? -1;
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
ShowError(Exceptions.dotnet_pack_failure.EscapeMarkup());
|
||||
if (exitCode != 0) {
|
||||
ShowError(Exceptions.dotnet_pack_failure.EscapeMarkup(), exitCode);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -270,7 +281,7 @@ public static class Program {
|
||||
try {
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(true)
|
||||
.HideCompleted(true)
|
||||
.HideCompleted(false)
|
||||
.Columns(new ProgressColumn[] {
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn()
|
||||
|
||||
Reference in New Issue
Block a user