Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/Stack/Git/ProcessHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static string ExecuteProcessAndReturnOutput(
}
else
{
throw new ProcessException(errorBuilder.ToString(), result);
throw new ProcessException(errorBuilder.ToString(), fileName, command, result);
}
}

Expand All @@ -85,14 +85,11 @@ public static string ExecuteProcessAndReturnOutput(
}
}

public class ProcessException : Exception
public class ProcessException(string message, string filePath, string command, int exitCode) : Exception(message)
{
public int ExitCode { get; }

public ProcessException(string message, int exitCode) : base(message)
{
ExitCode = exitCode;
}
public string FilePath { get; } = filePath;
public string Command { get; } = command;
public int ExitCode { get; } = exitCode;
}

internal static partial class LoggerExtensionMethods
Expand Down
14 changes: 12 additions & 2 deletions src/Stack/Infrastructure/Commands/Command.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.CommandLine;
using Microsoft.Extensions.Logging;
using Spectre.Console;
using Stack.Git;
using Stack.Infrastructure;
using Stack.Infrastructure.Settings;
Expand Down Expand Up @@ -42,7 +43,10 @@ public Command(
}
catch (ProcessException processException)
{
Logger.ErrorMessage(processException.Message);
Logger.ProcessExceptionCommandDetails(
Markup.Escape(processException.FilePath),
Markup.Escape(processException.Command));
Logger.ProcessExceptionErrorMessage(Markup.Escape(processException.Message));
return processException.ExitCode;
}
catch (OperationCanceledException)
Expand All @@ -51,7 +55,7 @@ public Command(
}
catch (Exception ex)
{
Logger.ErrorMessage(ex.Message);
Logger.ErrorMessage(Markup.Escape(ex.Message));
return 1;
}
});
Expand All @@ -64,6 +68,12 @@ public Command(

internal static partial class LoggerExtensionMethods
{
[LoggerMessage(Level = LogLevel.Error, Message = "An error occurred running command \"{FilePath} {Command}\"")]
public static partial void ProcessExceptionCommandDetails(this ILogger logger, string filePath, string command);

[LoggerMessage(Level = LogLevel.Debug, Message = "{Message}")]
public static partial void ProcessExceptionErrorMessage(this ILogger logger, string message);

[LoggerMessage(Level = LogLevel.Error, Message = "{Message}")]
public static partial void ErrorMessage(this ILogger logger, string message);
}
Loading