From c07ac0ac73343e0731d9d653d3f1c9fd81f7d8ed Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 9 Jul 2018 12:06:45 -0700 Subject: [PATCH 1/7] [Feature] Add more information to job process failure error --- .../fanin/OutOfProcTransportManager.cs | 21 +++++++++++++++++-- .../resources/RemotingErrorIdStrings.resx | 2 +- 2 files changed, 20 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 9fb08064270..7444fa12537 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -708,8 +708,25 @@ protected void OnExited(object sender, EventArgs e) // stdInWriter.StopWriting(); } - PSRemotingTransportException psrte = new PSRemotingTransportException(PSRemotingErrorId.IPCServerProcessExited, - RemotingErrorIdStrings.IPCServerProcessExited); + + int exitCode; + string exitMessage; + if (sender is Process jobProcess && jobProcess != null) + { + exitCode = jobProcess.ExitCode; + exitMessage = exitCode == 0 ? jobProcess.StandardOutput.ReadToEnd() : jobProcess.StandardError.ReadToEnd(); + } + else + { + exitCode = -1; + exitMessage = ""; + } + + string exitErrorMsg = StringUtil.Format(RemotingErrorIdStrings.IPCServerProcessExited, exitCode, exitMessage); + + 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 4d88df7d036..1cdced32c7e 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 with exit code {0} - information from process: '{1}'. There is an error processing data from the background process. Error reported: {0}. From 1f2ce02137c8ab31daf01ccd9d4b7e407c58036c Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 9 Jul 2018 12:14:07 -0700 Subject: [PATCH 2/7] [Feature] Make process reading code more robust with generic exception handling --- .../engine/remoting/fanin/OutOfProcTransportManager.cs | 7 ++++--- 1 file changed, 4 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 7444fa12537..ba1b87fd5fb 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -711,15 +711,16 @@ protected void OnExited(object sender, EventArgs e) int exitCode; string exitMessage; - if (sender is Process jobProcess && jobProcess != null) + try { + var jobProcess = (Process)sender; exitCode = jobProcess.ExitCode; exitMessage = exitCode == 0 ? jobProcess.StandardOutput.ReadToEnd() : jobProcess.StandardError.ReadToEnd(); } - else + catch (Exception exception) { exitCode = -1; - exitMessage = ""; + exitMessage = StringUtil.Format("", exception.Message); } string exitErrorMsg = StringUtil.Format(RemotingErrorIdStrings.IPCServerProcessExited, exitCode, exitMessage); From 909d68d1ef2802575ec2924c3840ffda29bf0f58 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 9 Jul 2018 20:10:31 -0700 Subject: [PATCH 3/7] [Feature] Add error messages to resource files, add stderr and stdout in all cases --- .../fanin/OutOfProcTransportManager.cs | 20 +++++++++++-------- .../resources/RemotingErrorIdStrings.resx | 8 +++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs index ba1b87fd5fb..d32644bfb1f 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -709,22 +709,26 @@ protected void OnExited(object sender, EventArgs e) stdInWriter.StopWriting(); } - int exitCode; - string exitMessage; + // Try to get details about why the process exited + // and if they're not available, give information as to why + string processFailureMessage; try { var jobProcess = (Process)sender; - exitCode = jobProcess.ExitCode; - exitMessage = exitCode == 0 ? jobProcess.StandardOutput.ReadToEnd() : jobProcess.StandardError.ReadToEnd(); + int exitCode = jobProcess.ExitCode; + processDiagnosticMessage = StringUtil.Format( + RemotingErrorIdStrings.ProcessExitInfo, + exitCode, + jobProcess.StandardOutput.ReadToEnd(), + jobProcess.StandardError.ReadToEnd()); } catch (Exception exception) { - exitCode = -1; - exitMessage = StringUtil.Format("", exception.Message); + string failureMessage = StringUtil.Format(RemotingErrorIdStrings.ProcessInfoNotRecoverable, exception.Message); + processDiagnosticMessage = StringUtil.Format(RemotingErrorIdStrings.IPCServerProcessExited, failureMessage); } - string exitErrorMsg = StringUtil.Format(RemotingErrorIdStrings.IPCServerProcessExited, exitCode, exitMessage); - + string exitErrorMsg = StringUtil.Format(RemotingErrorIdStrings.IPCServerProcessExited, processFailureMessage); var psrte = new PSRemotingTransportException( PSRemotingErrorId.IPCServerProcessExited, exitErrorMsg); diff --git a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx index 1cdced32c7e..83b02be2cfd 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 with exit code {0} - information from process: '{1}'. + The background process closed or ended abnormally: {0}. There is an error processing data from the background process. Error reported: {0}. @@ -1657,4 +1657,10 @@ 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}'. + From a8dd3592dd2bfb427d1eefb156130088478ed676 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 9 Jul 2018 20:17:20 -0700 Subject: [PATCH 4/7] [Feature] Fix error message when process read fails --- .../engine/remoting/fanin/OutOfProcTransportManager.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs index d32644bfb1f..692f46ef523 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -724,8 +724,7 @@ protected void OnExited(object sender, EventArgs e) } catch (Exception exception) { - string failureMessage = StringUtil.Format(RemotingErrorIdStrings.ProcessInfoNotRecoverable, exception.Message); - processDiagnosticMessage = StringUtil.Format(RemotingErrorIdStrings.IPCServerProcessExited, failureMessage); + processDiagnosticMessage = StringUtil.Format(RemotingErrorIdStrings.ProcessInfoNotRecoverable, exception.Message); } string exitErrorMsg = StringUtil.Format(RemotingErrorIdStrings.IPCServerProcessExited, processFailureMessage); From 049f5db4d6a942d08a148f54c0e80095bc050442 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 9 Jul 2018 20:21:07 -0700 Subject: [PATCH 5/7] [Feature] Fix compile errors, style issues --- .../remoting/fanin/OutOfProcTransportManager.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs index 692f46ef523..7de41fbfc61 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -711,23 +711,26 @@ protected void OnExited(object sender, EventArgs e) // Try to get details about why the process exited // and if they're not available, give information as to why - string processFailureMessage; + string processDiagnosticMessage; try { var jobProcess = (Process)sender; - int exitCode = jobProcess.ExitCode; processDiagnosticMessage = StringUtil.Format( RemotingErrorIdStrings.ProcessExitInfo, - exitCode, + jobProcess.ExitCode, jobProcess.StandardOutput.ReadToEnd(), jobProcess.StandardError.ReadToEnd()); } catch (Exception exception) { - processDiagnosticMessage = StringUtil.Format(RemotingErrorIdStrings.ProcessInfoNotRecoverable, exception.Message); + processDiagnosticMessage = StringUtil.Format( + RemotingErrorIdStrings.ProcessInfoNotRecoverable, + exception.Message); } - string exitErrorMsg = StringUtil.Format(RemotingErrorIdStrings.IPCServerProcessExited, processFailureMessage); + string exitErrorMsg = StringUtil.Format( + RemotingErrorIdStrings.IPCServerProcessExited, + processDiagnosticMessage); var psrte = new PSRemotingTransportException( PSRemotingErrorId.IPCServerProcessExited, exitErrorMsg); From 109ceeb6c3274e2e73c246d797f4fcc2d9ae282e Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 9 Jul 2018 20:22:02 -0700 Subject: [PATCH 6/7] [Feature] Fix more style issues --- .../engine/remoting/fanin/OutOfProcTransportManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs index 7de41fbfc61..652ed1f9fa7 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -732,8 +732,8 @@ protected void OnExited(object sender, EventArgs e) RemotingErrorIdStrings.IPCServerProcessExited, processDiagnosticMessage); var psrte = new PSRemotingTransportException( - PSRemotingErrorId.IPCServerProcessExited, - exitErrorMsg); + PSRemotingErrorId.IPCServerProcessExited, + exitErrorMsg); RaiseErrorHandler(new TransportErrorOccuredEventArgs(psrte, transportMethod)); } From fcad03fd543736881a8a7a362ea8170ffa89dee1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 10 Jul 2018 09:12:00 -0700 Subject: [PATCH 7/7] [Feature] Make process failure info multiline --- .../resources/RemotingErrorIdStrings.resx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx index 83b02be2cfd..981e28c6972 100644 --- a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx +++ b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx @@ -1658,7 +1658,11 @@ 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}'. + + Exit code: {0} + Stdout: '{1}' + Stderr: '{2}' + Information about the process could not be read: '{0}'.