choco icon indicating copy to clipboard operation
choco copied to clipboard

Very small but important: `Choco uninstall`: Please do not report an error if a package is not installed!

Open schittli opened this issue 3 years ago • 8 comments

What You Are Seeing?

If the user starts choco uninstall to uninstall Software which is not installed, then the user gets an error:

choco uninstall winrar
Chocolatey v0.10.15
Uninstalling the following packages:
winrar
winrar is not installed. Cannot uninstall a non-existent package.

What is Expected?

If choco uninstall notices that the software is not installed, then this is not an error but the user's desired goal has been successfully achieved.

When it is reported as an error, some users are concerned: "Dear IT, what went wrong here? Have I done something wrong?"

Therefore, choco uninstall should do not report an error in this case, please,

but report that the command was successful because the desired goal was reached.

For example, Choco could report something like this:

choco uninstall winrar
Chocolatey v0.10.15
Uninstalling the following packages:
winrar
OK (winrar was not installed)

How Did You Get This To Happen? (Steps to Reproduce)

choco uninstall winrar
Chocolatey v0.10.15
Uninstalling the following packages:
winrar
winrar is not installed. Cannot uninstall a non-existent package.

Thanks a lot! kind regards, Thomas

schittli avatar Nov 30 '21 14:11 schittli

One should not call uninstall if it's not installed: Don't change behavior, this is user error.

o-l-a-v avatar Dec 21 '21 11:12 o-l-a-v

It sounds like you're looking for some sort of idempotence here @schittli. This isn't what you'd use a configuration manager for. What I would suggest is that if users are managing packages from the command line they understand how to do so. So if they are trying to uninstall package that doesn't exist I would expect them to know what they are doing and understand the clear error message that Chocolatey displays winrar is not installed. Cannot uninstall a non-existent package.. That to me is fairly clear and shouldn't result in any calls to IT.

However, I can see both sides of this argument. What does concern me is that this is a breaking change. I wonder whether an enhanced exit code might work for this. However, in the scenario above, I don't think this would help.

pauby avatar Dec 21 '21 11:12 pauby

This appears to be a duplicate of #1451

TheCakeIsNaOH avatar Jan 16 '22 19:01 TheCakeIsNaOH

Idempotence is important for automation purposes. If there are concerns about breaking behavior, please consider adding a flag to enable this behavior, e.g.

choco uninstall --silent

yinso avatar Apr 03 '22 23:04 yinso

Idempotence is important for automation purposes. If there are concerns about breaking behavior, please consider adding a flag to enable this behavior, e.g.

choco uninstall --silent

Why can't you just automate detection first, then run uninstall only if detected?

--silent is not used to silence errors, traditionally.

o-l-a-v avatar Apr 04 '22 05:04 o-l-a-v

This is what the win_chocolatey Ansible module does; list local packages to determine if things are installed, and simply do nothing if you request uninstallation of a non-existent package. Others could do similar, for sure.

There's something to be said perhaps for an opt-in on commands more generally like --idempotent perhaps, but I don't think it's a hugely important thing; there are plentiful workarounds here at the moment that work just fine.

vexx32 avatar Apr 04 '22 13:04 vexx32

Why can't you just automate detection first, then run uninstall only if detected?

Detect then delete is not an atomic operation and could run into race conditions and isn't ideal. Granted it's less of an issue for low-concurrency systems like package management.

Also - people often have automation needs without being fluent in the stack involved (i.e. few people are shell experts). Detect then delete raises the effort for them considerably.

--silent is not used to silence errors, traditionally.

Just an example - I think rm uses --force. And strictly speaking, it's not an error as there is no state change; an FYI maybe.

yinso avatar Apr 26 '22 18:04 yinso

If choco uninstall notices that the software is not installed, then this is not an error but the user's desired goal has been successfully achieved.

How can Chocolatey know that? What if the user made a typo in the package ID, so for example tried to uninstall notpadplusplus instead of notepadplusplus. If Chocolatey continued on silently when a package was not found, then the user's desired goal would not have been successfully achieved, because the package they meant to uninstall (notepadplusplus) was still installed.

Not to say that an option like --skip-if-not-installed or --ignore-unfound is a bad idea, due to the aforementioned automation idempotence reason.

TheCakeIsNaOH avatar Aug 04 '22 22:08 TheCakeIsNaOH

I'm going to close this as, on balance, it isn't something we'd be looking to implement.

pauby avatar Aug 10 '22 15:08 pauby