-
Notifications
You must be signed in to change notification settings - Fork 342
Fix removing batch redirects when uninstalling a package #418
Fix removing batch redirects when uninstalling a package #418
Conversation
…Bins This fixes batch redirect files not being removed when uninstalling a package (a bug introduced by b12e91b "add error level checking..."). Invoke-ChocolateyFunction uses the splatting operator ("@") to pass parameters to the invoked function. When the parameter values are passed to Invoke-ChocolateyFunction encapsulated in an array, the splatting operator matches them only to positional parameters of the invoked function. In order to pass values of named parameters and/or switches, they need to be encapsulated in a hashtable.
…directs Otherwise they would get silently swallowed with no chance of debugging.
- print parameters passed as hashtable correctly - nicely format parameter values, so that the output resembles the actual syntax that would be used when invoking the function directly
the purpose of that commit functionality comes from a requirement to be integrated in a non interactive environment. if the functions blindly exit state 0s without exception raising then any automation around chocolatey where failures occur, the errors will be swallowed. the outer lying tool will think everything was honky dory, when in reality failures occured. |
all for the hashtables btw :) |
The current implementation of Your original implementation would indeed use the Having said that, you certainly have a point about returning an error code when something goes wrong. Powershell not doing that is actually a deficiency of powershell.exe when invoked with the
this correctly returns a nonzero exit code if the script encounters an error. Please also note that some ("non-terminating") errors are subject to $ErrorHandlingPreference; I usually set it to "Stop" (most restrictive) immediately at the beginning of my scripts, so all errors behave like exceptions (e.g. transfer control to the nearest catch clause). |
imho the mandatory exit is the right and default behavior. i agree a switch show control -ignorefailures... i am a big proponent of fail early and stop all things. right now for better or worse its being called from puppet via chocolatey.cmd. that uses -command |
My point is, with an exit deep inside an internal function, there would be no way to implement that switch. Also, when an error is encountered during the installation, there is usually some cleanup to be performed, such as deleting the failed package from $Env:ChocolateyInstall\lib. I also believe in failing early, but in a controllable fashion. I would not like it, for example, if fopen() called ExitProcess() if it failed to open the file. |
agree with you 100%. Inserting proper exception management is needed. My short term goal was selfish, get the error out. Improvement is def needed and i think choco has longer term plans to go c# which will probably help resiliency overall. |
I too think that Are there any plans merging the fixes jberezanski made? It's really annoying that uninstalling something does not remove the batch redirects. |
ok someone submit pr and make sure non exit 0 is bubbled all the way back out to cmd/posh on any failure. |
I don't want to argue and am not that familiar with powershell, but when i look at the code:
It seems obvious to me that this is just a |
Currently, when a package is uninstalled, instead of removing batch redirect files from $Env:ChocolateyInstall\bin, Chocolatey recreates them (acts as if the package was being installed).
This happens because the "uninstall" switch is being passed to Get-ChocolateyBins incorrectly (bug introduced by commit b12e91b "add error level checking to chocolatey install process (nuget)").
That commit wrapped the Get-ChocolateyBins call with Invoke-ChocolateyFunction, but passed the parameter values wrapped in an array, which works for positional parameters only. The solution is to use a hashtable (a good practice anyway, since the code is more maintainable).
As a side note, apart from (now a bit improved) logging of parameter values for diagnostic purposes, Invoke-ChocolateyFunction does not seem to add any other value, but only introduces complexity, increases possibility of bugs and prevents IntelliSense when editing the scripts. I'd gladly see it removed.