Search code examples
powershellchocolatey

Track chocolatey error


I am installing a chocolatey package, which throws an error:

Write-Error : [ERROR] Running C:\Users\username\AppData\Local\Temp\chocolatey\javaruntime\javaruntimeInstall.exe with /s REBOOT=Suppress  was not successful. Exit code was '1603'.
At C:\ProgramData\chocolatey\chocolateyinstall\helpers\functions\Start-ChocolateyProcessAsAdmin.ps1:46 char:5
+     Write-Error $errorMessage
+     ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Write-Error

Write-Error : javaruntime did not finish successfully. Boo to the chocolatey gods!
-----------------------

The error is shown in the console, but I can't find a way to track it. The exit code after cinst javaruntime -force is 0 and the package gets moved to C:\ProgramData\chocolatey\lib-bad. I already tried to catch the error with try-catch but cinst simply skips it and gets excuted after the try-catch block.

Is there any way to track such errors?

UPDATE to clarify: My problem is, that chocolatey exits with tho code 0, even though there was an error and the package gets moved to lib-bad.

Thanks for your help :D


Solution

  • Do you mean you want the error code to bubble up as the exit code from Chocolatey? The POSH version doesn't always correctly capture the error code from the running the package install.

    This is fixed in the new C# version (not yet out as of 09/15/2014).

    UPDATE: Choco 0.9.9.x will exit with 0/1. Choco 0.9.10.x will exit with same exit code as the package. This allows reboot scenarios to bubble up to the calling process, if it is an infrastructure management solution.