From 6a66a6e0f09edc123914559b3eab5d5cf66aab84 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 11 Jul 2018 20:06:07 -0700 Subject: [PATCH] Add more information to job process failure error (#7251) --- .../fanin/OutOfProcTransportManager.cs | 28 +++++++++++++++++-- .../resources/RemotingErrorIdStrings.resx | 12 +++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs index 9fb0806427..652ed1f9fa 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -708,8 +708,32 @@ namespace System.Management.Automation.Remoting.Client // stdInWriter.StopWriting(); } - PSRemotingTransportException psrte = new PSRemotingTransportException(PSRemotingErrorId.IPCServerProcessExited, - RemotingErrorIdStrings.IPCServerProcessExited); + + // Try to get details about why the process exited + // and if they're not available, give information as to why + string processDiagnosticMessage; + try + { + var jobProcess = (Process)sender; + processDiagnosticMessage = StringUtil.Format( + RemotingErrorIdStrings.ProcessExitInfo, + jobProcess.ExitCode, + jobProcess.StandardOutput.ReadToEnd(), + jobProcess.StandardError.ReadToEnd()); + } + catch (Exception exception) + { + processDiagnosticMessage = StringUtil.Format( + RemotingErrorIdStrings.ProcessInfoNotRecoverable, + exception.Message); + } + + string exitErrorMsg = StringUtil.Format( + RemotingErrorIdStrings.IPCServerProcessExited, + processDiagnosticMessage); + var psrte = new PSRemotingTransportException( + PSRemotingErrorId.IPCServerProcessExited, + exitErrorMsg); RaiseErrorHandler(new TransportErrorOccuredEventArgs(psrte, transportMethod)); } diff --git a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx index 3096b5b8c4..bd712339b7 100644 --- a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx +++ b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx @@ -794,7 +794,7 @@ Do you want to continue? The background process reported an error with the following message: {0}. - The background process closed or ended abnormally. + The background process closed or ended abnormally: {0}. There is an error processing data from the background process. Error reported: {0}. @@ -1657,4 +1657,14 @@ All WinRM sessions connected to PowerShell session configurations, such as Micro This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system. + + + Exit code: {0} + Stdout: '{1}' + Stderr: '{2}' + + + + Information about the process could not be read: '{0}'. +