Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Chocolatey-Install should return non-zero exit code if chocolateyInstall.ps1 fails #568

Closed
warnergodfrey opened this issue Sep 8, 2014 · 8 comments

Comments

@warnergodfrey
Copy link

If a package's install script fails and exits with a non-zero exit code then choco install still returns with a zero exit code. This behaviour is consistent in both v0.9.8.27 and v0.9.8.28-alpha2.

Run-ChocolateyPS1 throws an error if the chocolateyInstall.ps1 or chocolateyUninstall.ps1 fails, however the Chocolatey-NuGet.ps1 swallows the exception. The exception should bubble up and cause the choco command to fail.

@warnergodfrey warnergodfrey changed the title Chocolatey-Install should return non-zero exit code if cocololateyInstall.ps1 fails Chocolatey-Install should return non-zero exit code if cocolateyInstall.ps1 fails Sep 8, 2014
@warnergodfrey warnergodfrey changed the title Chocolatey-Install should return non-zero exit code if cocolateyInstall.ps1 fails Chocolatey-Install should return non-zero exit code if chocolateyInstall.ps1 fails Sep 8, 2014
@ferventcoder
Copy link
Contributor

Agreed.

@ferventcoder
Copy link
Contributor

I wonder if the chocolateyInstall.ps1 is swallowing the error...

@bmedlin
Copy link

bmedlin commented Jan 14, 2015

I've had the same problem. The exception thrown from my package's chocolateyInstall.ps1 is not bubbling up - it is being caught in Chocolatey-Nuget.ps1 and not re-thrown (~line 93). There appears to be an attempt to fail the package by setting $chocolateyErrored to $true, but this variable is false again by the time it is evaluated in chocolatey.ps1. Re-throwing the exception appears to resolve the issue.

@ferventcoder
Copy link
Contributor

@warnergodfrey @bmedlin I believe this was just fixed by @mwrock in a recent PR.

@ferventcoder
Copy link
Contributor

#658

@mwrock
Copy link
Contributor

mwrock commented Jan 14, 2015

my PR addresses the exit code but does not rethrow. Honestly I personally prefer actually rethrowing the actual exception. For something like Boxstarter which calls the chocolatey powershell functiuons directly, I can better inspect the exception and provide better logging. I realize that will no longer be possible with choco.exe.

Another PR I considered was adding more detail to the exceptions logged. Currently chocolotey just captures the error message which is sometimes not very helpful. Doing something like logging:

$_.exception | fl * -force | out-string

would capture any stacktrace and inner exceptions and even script level stack trace on later OSs. I'm probably gonna hold off on contributing that until the new chocolatey comes out but this is my 2 cents. :)

Also, chocolatey simply returns an exit code of 1 and it would be better to at least return the original exit code. My PR was just an attempt to "fix" what appeared to be the current intent of the code. On the boxstarter side I can always just examine the $errors array to grab the full exceptions after the fact. Again, that only works if you are calling chocolatey from powershell and calling the actual powershell functions so you are not crossing any process boundaries.

@ferventcoder
Copy link
Contributor

@mwrock where would you put that bit of code?

@ferventcoder
Copy link
Contributor

@mwrock nevermind, found a good spot. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants