未验证 提交 301774db 编写于 作者: J Jo Shields 提交者: GitHub

Be more verbose when processes spawned from tasks fail. (#54144)

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.
上级 f7d48720
......@@ -33,7 +33,6 @@ public static string GetEmbeddedResource(string file)
{
LogInfo($"Running: {path} {args}", debugMessageImportance);
var outputBuilder = new StringBuilder();
var errorBuilder = new StringBuilder();
var processStartInfo = new ProcessStartInfo
{
FileName = path,
......@@ -72,9 +71,8 @@ public static string GetEmbeddedResource(string file)
if (!silent)
{
LogWarning(e.Data);
outputBuilder.AppendLine(e.Data);
}
errorBuilder.AppendLine(e.Data);
outputBuilder.AppendLine(e.Data);
}
};
process.OutputDataReceived += (sender, e) =>
......@@ -84,8 +82,8 @@ public static string GetEmbeddedResource(string file)
if (!silent)
{
LogInfo(e.Data, outputMessageImportance);
outputBuilder.AppendLine(e.Data);
}
outputBuilder.AppendLine(e.Data);
}
};
process.BeginOutputReadLine();
......@@ -96,10 +94,10 @@ public static string GetEmbeddedResource(string file)
{
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册