Skip to content
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

Unswallow uninstall error #2707

Merged
1 commit merged into from Apr 2, 2019
Merged

Unswallow uninstall error #2707

1 commit merged into from Apr 2, 2019

Conversation

deivid-rodriguez
Copy link
Member

Description:

Sometimes gem uninstall <gem_name> fails to uninstall the gem, but does not give any errors. See #2701.

This error swallowing seems intentionally introduced specifically for the --all option in 564ffe2, but I don't think this is good. In that case, --all is leaving gems around so the user should be informed too?

Maybe gem uninstall should try all paths in GEM_PATH instead?

Not sure, but the current behavior is no good.

Tasks:

  • Describe the problem / feature
  • Write tests
  • Write code to solve the problem
  • Get code review from coworkers / friends

I will abide by the code of conduct.

@deivid-rodriguez
Copy link
Member Author

/cc @eregon

@deivid-rodriguez deivid-rodriguez changed the title Unswallow install error Unswallow uninstall error Mar 29, 2019
@deivid-rodriguez
Copy link
Member Author

If we want to get this in quickly without changing any behavior, I can also scope the swallowing to the --all option only.

@deivid-rodriguez
Copy link
Member Author

We should fix the culprit of the error though, I'll try to figure out why this is succeeding under some version manager and failing on others.

@deivid-rodriguez
Copy link
Member Author

deivid-rodriguez commented Mar 29, 2019

Ok. So the explanation is that by default gem uninstall tries to uninstall from GEM_HOME and Gem.user_dir.

On a bare ruby installation, Gem.paths.path - [Gem.paths.home] == [Gem.user_dir] is true, so the uninstall succeeds. But on rvm, Gem.user_dir is a different directory not included in GEM_PATH, so uninstall fails because the uninstall command never looks in the proper location.

@eregon
Copy link
Contributor

eregon commented Mar 29, 2019

@deivid-rodriguez It's not urgent, I have a workaround, let's find a proper fix.

@eregon
Copy link
Contributor

eregon commented Mar 29, 2019

I think in all cases we'd want error messages to at least be printed to let the user know, so this fix looks good to me.

@eregon
Copy link
Contributor

eregon commented Mar 29, 2019

Ok. So the explanation is that by default gem uninstall tries to uninstall from GEM_HOME and Gem.user_dir.

On a bare ruby installation, Gem.paths.path - [Gem.paths.home] == [Gem.user_dir] is true, so the uninstall succeeds. But on rvm, Gem.user_dir is a different directory not included in GEM_PATH, so uninstall fails because the uninstall command never looks in the proper location.

That's surprising. Maybe Gem.user_dir shouldn't be considered here, because we want to install/uninstall from some directory of the GEM_PATH/Gem.path, but not outside of that, isn't it? (except maybe if specifically requested with --install-dir)
Or alternatively, if Gem.user_dir maybe it should always be part of Gem.path then?

@deivid-rodriguez
Copy link
Member Author

deivid-rodriguez commented Mar 29, 2019

Yeah, apparently this is optional

add_option('--[no-]user-install',
'Uninstall from user\'s home directory',
'in addition to GEM_HOME.') do |value, options|
options[:user_install] = value
end

And defaults to true

:version => Gem::Requirement.default, :user_install => true,

I'm not really sure how Gem.user_dir is used in other parts of rubygems. I was definitely surprised too when I found out about it being considered, yeah. But I was not surprised when gem uninstall succeeded while trying to reproduce this issue. So, I guess my naive expectation is that all paths in GEM_PATH are considered, not only GEM_HOME.

Copy link
Member

@hsbt hsbt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems reasonable. We shouldn't ignore exception warnings.

@deivid-rodriguez
Copy link
Member Author

Let's do this then!

@bundlerbot r=hsbt

ghost pushed a commit that referenced this pull request Apr 2, 2019
2707: Unswallow uninstall error r=hsbt a=deivid-rodriguez

# Description:

Sometimes `gem uninstall <gem_name>` fails to uninstall the gem, but does not give any errors. See #2701.

This error swallowing seems intentionally introduced specifically for the `--all` option in 564ffe2, but I don't think this is good. In that case, `--all` is leaving gems around so the user should be informed too?

Maybe `gem uninstall` should try all paths in `GEM_PATH` instead?

Not sure, but the current behavior is no good.


# 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).


Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
@ghost
Copy link

ghost commented Apr 2, 2019

Build succeeded

@ghost ghost merged commit 7e27b99 into master Apr 2, 2019
@ghost ghost deleted the unswallow_install_error branch April 2, 2019 09:59
@eregon
Copy link
Contributor

eregon commented Apr 2, 2019

Thanks for the fix!

@hsbt hsbt added this to the 3.0.5 milestone Aug 2, 2019
hsbt pushed a commit that referenced this pull request Aug 16, 2019
2707: Unswallow uninstall error r=hsbt a=deivid-rodriguez

# Description:

Sometimes `gem uninstall <gem_name>` fails to uninstall the gem, but does not give any errors. See #2701.

This error swallowing seems intentionally introduced specifically for the `--all` option in 564ffe2, but I don't think this is good. In that case, `--all` is leaving gems around so the user should be informed too?

Maybe `gem uninstall` should try all paths in `GEM_PATH` instead?

Not sure, but the current behavior is no good.


# 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).


Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
@aried3r
Copy link

aried3r commented Aug 20, 2019

Hey, we're currently facing CI issues in rails/webpacker#2243. I know this is because we cannot (yet) support bundler 2.0 in that repo in all cases and thus is not directly a bug, but it's still backwards incompatible behavior, in case the CLI is considered public API.

I guess we're hitting this new behavior here and can just || true in this case? I don't necessarily advocate for rolling back this PR, since it actually fixes bugs, we were just caught off-guard by the change.

@deivid-rodriguez
Copy link
Member Author

Yeah, @aried3r, I'm sorry we broke your CI...

There's always a fine line between backwards incompatibility and bug fixes, because every change in the code, even bug fixes, change the behaviour of programs. In this case, we've chosen to consider this a bug fix, and thus ship it in a patch release.

If you want your CI to be locked, and only upgrade whenever you want to / need to, you can lock the rubygems version in your CI with gem update --system 3.0.6.

Hope it helps!

@aried3r
Copy link

aried3r commented Aug 20, 2019

No worries, just wanted to make sure we actually know why it happened. Thanks for your quick reply and your and everybody else's work on rubygems!

ghost pushed a commit that referenced this pull request Aug 27, 2019
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>
aried3r added a commit to rpush/rpush that referenced this pull request Sep 4, 2019
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] rubygems/rubygems#2707
[1] rubygems/rubygems#2893
Adrian1707 pushed a commit to Adrian1707/rpush that referenced this pull request Apr 24, 2024
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] rubygems/rubygems#2707
[1] rubygems/rubygems#2893
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants