Skip to content

Commit

Permalink
Be more verbose when processes spawned from tasks fail. (dotnet#54144)
Browse files Browse the repository at this point in the history
Right now, when a process fails (e.g. cmake or xcodebuild), all of the STDERR captured during that process run is dumped in the exception.

However, if silent is true, no STDOUT is captured at all, and we lose potentially vital debugging information contained within.

This PR merges the stdout and stderr capture, and instead of not capturing anything when silent is true, it always captures and only returns nothing when silent is true.

This should greatly ease debugging of failed tasks.
  • Loading branch information
directhex authored Jun 15, 2021
1 parent f7d4872 commit 301774d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/tasks/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static string RunProcess(
{
LogInfo($"Running: {path} {args}", debugMessageImportance);
var outputBuilder = new StringBuilder();
var errorBuilder = new StringBuilder();
var processStartInfo = new ProcessStartInfo
{
FileName = path,
Expand Down Expand Up @@ -72,9 +71,8 @@ public static string RunProcess(
if (!silent)
{
LogWarning(e.Data);
outputBuilder.AppendLine(e.Data);
}
errorBuilder.AppendLine(e.Data);
outputBuilder.AppendLine(e.Data);
}
};
process.OutputDataReceived += (sender, e) =>
Expand All @@ -84,8 +82,8 @@ public static string RunProcess(
if (!silent)
{
LogInfo(e.Data, outputMessageImportance);
outputBuilder.AppendLine(e.Data);
}
outputBuilder.AppendLine(e.Data);
}
};
process.BeginOutputReadLine();
Expand All @@ -96,10 +94,10 @@ public static string RunProcess(
{
Logger?.LogMessage(MessageImportance.High, $"Exit code: {process.ExitCode}");
if (!ignoreErrors)
throw new Exception("Error: Process returned non-zero exit code: " + errorBuilder);
throw new Exception("Error: Process returned non-zero exit code: " + outputBuilder);
}

return outputBuilder.ToString().Trim('\r', '\n');
return silent ? string.Empty : outputBuilder.ToString().Trim('\r', '\n');
}

#if NETCOREAPP
Expand Down

0 comments on commit 301774d

Please sign in to comment.