Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skyline: Include process output in ProcessRunner exceptions when it… #2731

Merged
merged 5 commits into from
Oct 2, 2023
24 changes: 24 additions & 0 deletions pwiz_tools/Shared/CommonUtil/SystemUtil/ProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ public static bool GoodIfExitCodeIsZero(string stderr, int exitCode)
}
}

StringBuilder sbOutput = null;
if (writer == null)
{
sbOutput = new StringBuilder();
writer = new StringWriter(sbOutput);
}

try
{
var reader = new ProcessStreamReader(proc, StatusPrefix == null && MessagePrefix == null);
Expand Down Expand Up @@ -215,6 +222,13 @@ public static bool GoodIfExitCodeIsZero(string stderr, int exitCode)
}

}
catch (Exception ex) // CONSIDER: Should we handle more types like WrapAndThrowException does?
{
if (sbOutput != null)
brendanx67 marked this conversation as resolved.
Show resolved Hide resolved
ThrowExceptionWithOutput(ex, sbOutput.ToString());

throw;
}
finally
{
if (!proc.HasExited)
Expand All @@ -224,6 +238,16 @@ public static bool GoodIfExitCodeIsZero(string stderr, int exitCode)
}
}

private void ThrowExceptionWithOutput(Exception exception, string output)
{
var sbText = new StringBuilder();
sbText.AppendLine(exception.Message)
.AppendLine()
.AppendLine("Output:")
.AppendLine(output);
throw new IOException(exception.Message, new IOException(sbText.ToString(), exception));
}

// Clean out any tempfiles left behind, if forceTempfilesCleanup was set
private void CleanupTmpDir()
{
Expand Down