-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve gem uninstall --all
#2893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
If we did this, and released it with 3.0.7, we'll probably save some people from having to change some CI scripts. |
hsbt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer "after behavior"
a502ff5 to
534df70
Compare
| end | ||
|
|
||
| if list.empty? | ||
| raise Gem::InstallError, "gem #{@gem.inspect} is not installed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you think we could instead have an error class Gem::UninstallError when we do uninstall?
It is probably a breaking change... :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, it was very confusing the first time I saw this. I'll try to change this in the future.
|
Thanks a lot for the quick PR @deivid-rodriguez and @hsbt for the review. 🙏 |
Instead, display an informative message saying that uninstallation of specific versions is being skipped because of being default gems.
534df70 to
b44845a
Compare
bronzdoc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @deivid-rodriguez !
|
@bundlerbot r+ |
2893: Improve `gem uninstall --all` r=bronzdoc a=deivid-rodriguez # Description: After we started unswallowing errors of `gem uninstall` in #2707, some people got failing CI runs because they were doing things like `gem uninstall <default_gem> --all --force`. Previously that would work just fine, because the error while trying to uninstall a default gem was being swallowed. In my opinion, if you try to do `gem uninstall bundler:1.17.2` (on a ruby where this is the default bundler version), then it is fine to fail hard, but if you do `gem uninstall bundler --all`, then the command should uninstall all bundler versions that can be uninstalled (and skip the default version), but not fail just because bundler is a default gem. It can be argued though that the command should indeed fail hard, because it didn't really succeeded on trying to do what the user asked for: the user tried to uninstall _all_versions, but that wasn't achieved because the default version was left around. In order to find a compromise between these two visions, and maximize usability, I propose to not fail hard, but log a line for each default version that couldn't be removed. Note that the current behavior is completely inconsistent (in my opinion), because it fails if the default copy is the single copy in the system, but succeeds if it's not: ``` $ gem uninstall rdoc --all --force ERROR: While executing gem ... (Gem::InstallError) gem "rdoc" cannot be uninstalled because it is a default gem $ gem install rdoc Fetching rdoc-6.1.1.gem Successfully installed rdoc-6.1.1 1 gem installed $ gem uninstall rdoc --all --force Successfully uninstalled rdoc-6.1.1 ``` After this PR, the messages are more consistent and informative, in my opinion, and the status code is always success (as it was before #2707). ``` $ ruby -Ilib bin/gem uninstall rdoc --all --force Ignored rdoc-6.1.0 because it is a default gem $ gem install rdoc Fetching rdoc-6.1.1.gem Successfully installed rdoc-6.1.1 1 gem installed $ ruby -Ilib bin/gem uninstall rdoc --all --force Ignored rdoc-6.1.0 because it is a default gem Successfully uninstalled rdoc-6.1.1 ``` Thoughts? # Tasks: - [x] Describe the problem / feature - [x] Write tests - [x] Write code to solve the problem - [ ] Get code review from coworkers / friends I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md). Closes #2892. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
Build succeeded |
A change in rubygems [0] made our CI fail, but since it was every run, it showed that this line was indeed not needed. A fix in a future rubygems version [1] should fix this as well, but I think this is the way to go. [0] ruby/rubygems#2707 [1] ruby/rubygems#2893
A change in rubygems [0] made our CI fail, but since it was every run, it showed that this line was indeed not needed. A fix in a future rubygems version [1] should fix this as well, but I think this is the way to go. [0] ruby/rubygems#2707 [1] ruby/rubygems#2893
Description:
After we started unswallowing errors of
gem uninstallin #2707, some people got failing CI runs because they were doing things likegem uninstall <default_gem> --all --force. Previously that would work just fine, because the error while trying to uninstall a default gem was being swallowed.In my opinion, if you try to do
gem uninstall bundler:1.17.2(on a ruby where this is the default bundler version), then it is fine to fail hard, but if you dogem uninstall bundler --all, then the command should uninstall all bundler versions that can be uninstalled (and skip the default version), but not fail just because bundler is a default gem.It can be argued though that the command should indeed fail hard, because it didn't really succeeded on trying to do what the user asked for: the user tried to uninstall _all_versions, but that wasn't achieved because the default version was left around.
In order to find a compromise between these two visions, and maximize usability, I propose to not fail hard, but log a line for each default version that couldn't be removed.
Note that the current behavior is completely inconsistent (in my opinion), because it fails if the default copy is the single copy in the system, but succeeds if it's not:
After this PR, the messages are more consistent and informative, in my opinion, and the status code is always success (as it was before #2707).
Thoughts?
Tasks:
I will abide by the code of conduct.
Closes #2892.