ChocolateyInstall.ps1 is not returning exit codes to the BAT scripts #384
Comments
This may or may not have been fixed in source... Thanks for adding the issue though. |
I can confirm that the cpack command doesn't return the error code that I am expecting:
I am using 0.9.8.23. EDIT: This is covered by Issue #256. |
so if you call |
nuget.exe returns 1:
Note that I manufactured the error in both cases to test the return code by editing my nuspec file to be invalid XML. |
I've written a failing test. I've never used pester before, but hopefully it is correct... Describe "When calling cpack with an invalid nuspec" {
cpack 'c:\some\bogus\path'
$cinstExitCode = $LASTEXITCODE
It "should return a non-zero exit code" {
$cinstExitCode | Should Not Be 0
}
} |
Awesome. If you want to take that a step further and provide the fix in a pull request with the tests to prove it, it gets pulled in quite a bit quicker. Also review the contributing guide https://github.com/chocolatey/chocolatey/blob/master/CONTRIBUTING.md |
I've had a go at this, but am struggling to come up with a valid solution and test.
The only viable solution I can think of (but haven't tried yet) is to mock out Start-Process and Get-Content and call Chocolatey-Pack directly to ensure that it throws an exception. Unfortunately, it is possible for a regression to appear in the .bat file or exception handling some time in the future because this is not a complete end-to-end test. My questions are, do you think this solution is viable, and do you think it is sufficient? Note: this is my proposed fix (without test): diff --git a/src/functions/Chocolatey-Pack.ps1 b/src/functions/Chocolatey-Pack.ps1
index c46b2f1..4122389 100644
--- a/src/functions/Chocolatey-Pack.ps1
+++ b/src/functions/Chocolatey-Pack.ps1
@@ -18,7 +18,6 @@ param(
}
$errors = Get-Content $errorLogFile
if ($errors -ne '') {
- Write-Host $errors -BackgroundColor Red -ForegroundColor White
- #throw $errors
+ throw $errors
}
}
\ No newline at end of file |
I would also need to look into why we commented that out. |
Going back in time here....: |
Is this still related to the error not getting returned when install
|
@codearoo Ha, looks like we hijacked this thread. I didn't even pay attention to what the main issue was that was reported. |
Looks like #256 is what we're discussing here... |
I believe this is now fixed |
To avoid forgetting about this, I'm logging this issue. I have already discussed with Rob and he acknowledged.
If you run something like 'cinst yyyy' where yyyy is a package that fails to install but DOES EXIST in Chocolatey, it will not trap any errors, and the %errorlevel% after it will always be 0.
If you run 'cinst xxxx' where xxx is some package it can't find, it DOES work correctly:
C:\Users\Administrator>cinst sadfsdfsd
Chocolatey (v0.9.8.23) is installing 'sadfsdfsd' and dependencies. By installing
you accept the license for 'sadfsdfsd' and each dependency you are installing.
Unable to find package 'sadfsdfsd'.
Command 'install' failed (sometimes this indicates a partial failure). Additiona
l info/packages: sadfsdfsd
Reading environment variables from registry. Please wait... Done.
C:\Users\Administrator>echo %errorlevel%
1
And by the way, 'cinst tunnelier' 'cinst vim' always fail on Win2008R1 on Choco 0.9.8.23, but did not fail with older versions. It seems like there is bunch of stuff that just is not working on Win2008R1.. maybe you should advertise that on the main site unless you fix it.
The text was updated successfully, but these errors were encountered: