BrightLight / RepoCop

RepoCop is a repository hook framework written in C#
3 stars 2 forks source link

CommandLineInstruction: add more logging #4

Closed BrightLight closed 8 months ago

BrightLight commented 6 years ago

If the CommandLineInstruction does not work there's no way to know what happened. It should at least log the command line that is executed, ideally also any standard or error output (which is already prepared in the code, but doesn't seem to be used).

BrightLight commented 8 months ago

If the exit code differs from the expected exit code, CommandLineInstructions.ExecuteWaitForExitInstruction now logs a warning which includes the filename and the arguments. This should improve troubleshooting.

var wasSuccess = process.ExitCode == this.ExpectedExitCode;
if (!wasSuccess)
{
  var logMessage = $"Process exited with unexpected exit code [{process.ExitCode}]. Expected exit code was [{this.ExpectedExitCode}].\n"
    + $"Filename: [{processStartInfo.FileName}]\n"
    + $"Arguments: [{processStartInfo.Arguments}]";
  log.WarnFormat(logMessage);
}

Doesn't work for ExecuteFireAndForgetInstruction because we just call the process and then don't care anymore.