Skip to content

Commit

Permalink
(GH-249) Fix "operation completed successfully" on stderr
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed Jun 13, 2015
1 parent 83e1105 commit 9936876
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/chocolatey/infrastructure.app/services/PowershellService.cs
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9936876

Please sign in to comment.