From 99368761de360b3f20745995c19b9bddbb1fa51a Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 12 Jun 2015 20:11:14 -0500 Subject: [PATCH] (GH-249) Fix "operation completed successfully" on stderr It seems that many applications out there can return this error and still exit with a zero exit code, when this is logged within the PowerShell service runner, it should redirect that back to the info stream and not count it as a fail point. If PowerShell does exit with a non-zero status, then we should count the whole install as a failure no matter what messages were logged. In this way the exit code 0 and the message "The operation completed successfully" are not considered a failure. References: https://rcmtech.wordpress.com/2012/03/06/vbscript-and-reg_binary-registry-values/ http://en.community.dell.com/techcenter/powergui/f/4833/t/19570669 >I've found the problem. The main problem is in reg.exe utility. >Depending on the version reg.exe utility works differently. v5.1.x.x (that I have on my XPSP3) works correctly, but v5.2.x.x does not work as it is expected to work. >"reg import" command: >- when v5.1: returns "Operation completed successfully" to standard OUTPUT stream >- when v5.2: returns "Operation completed successfully" to standard ERROR stream >Moreover, it is probably a problem with PowerShell also :( >PowerShell treats these streams differently and process ERROR stream messages as errors. Which is correct imho. --- .../services/PowershellService.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index 16d0f43763..2f9259d100 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -31,6 +31,7 @@ public class PowershellService : IPowershellService { private readonly IFileSystem _fileSystem; private readonly string _customImports; + private const string OPERATION_COMPLETED_SUCCESSFULLY = "The operation completed successfully."; public PowershellService(IFileSystem fileSystem) : this(fileSystem, new CustomString(string.Empty)) @@ -269,10 +270,22 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack (s, e) => { if (string.IsNullOrWhiteSpace(e.Data)) return; - failure = true; - this.Log().Error(() => " " + e.Data); + if (e.Data.is_equal_to(OPERATION_COMPLETED_SUCCESSFULLY)) + { + this.Log().Info(() => " " + e.Data); + } + else + { + failure = true; + this.Log().Error(() => " " + e.Data); + } }); + if (exitCode != 0) + { + failure = true; + } + if (failure) { Environment.ExitCode = exitCode;