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

Avoid error reporting relative path when validating frozen #5128

Conversation

yaauie
Copy link
Contributor

@yaauie yaauie commented Dec 2, 2021

When invoking Bundler::Runtiume::setup on a frozen bundle, and there is no
relative path from PWD to our default lockfile, our attempt to pre-generate a
helpful message results in an ArgumentError.

This is more likely to occur on Windows, for example if PWD is on the C:
volume and our project is on the D: volume, our application entry-point is
invoked using an absolute path, and our application invokes Bundler::setup.

What was the end-user or developer problem that led to this PR?

A customer invoking Logstash 7.15.x using an absolute path D:\logstash-7.15.0\bin\logstash from a shell whose PWD was on the C:\ volume resulted in an ArgumentError propagating up from Bundler::Definition#ensure_equivalent_gemfile_and_lockfile. Logstash invokes Bundler directly in code with :frozen attribute set to true.

What is your fix for the problem, implemented in this PR?

Stdlib's Pathname#relative_path_from raises an ArgumentError if it cannot give a relative path.

Since Bundler's usage doesn't actually require a relative path but is only meant to provide helpful guidance to the user should our invocation eventually fail, it makes sense to rescue the ArgumentError and simply use the absolute path when a relative path can't be built.

I would appreciate guidance on how to write a test for this. Bundler::Definition#ensure_equivalent_gemfile_and_lockfile does not appear to be covered at all in unit tests, and in any case there are likely to be OS-specific instructions for what constitutes a different base (on my POSIX machine running jruby, I cannot get Pathname#relative_path_from to produce the same ArgumentError).

Make sure the following tasks are checked

@welcome
Copy link

welcome bot commented Dec 2, 2021

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

@deivid-rodriguez
Copy link
Member

Normally bundler uses end to end specs. I would grep specs for this specific error message and use the result as a base to reproduce this particular realworld situation (or a simplified version of it).

The changes look good to me, by the way!

@deivid-rodriguez deivid-rodriguez changed the title bundler: avoid error reporting relative path when validating frozen Avoid error reporting relative path when validating frozen Dec 2, 2021
deivid-rodriguez and others added 2 commits September 25, 2023 10:27
When a path does not make a lot of sense.
To avoid potential crashes when trying to jump from a drive to another
on Windows, and take the change refactor things a bit.
@deivid-rodriguez deivid-rodriguez force-pushed the bundler-frozen-lockfile-no-relative-path branch from e365121 to 7c9a9a4 Compare September 25, 2023 08:30
@deivid-rodriguez
Copy link
Member

Actually one of our Windows specs just reproduced this error. See #6989.

So I went ahead and edited this PR so that this similar error you were running into is also prevented.

@deivid-rodriguez
Copy link
Member

Thanks!

@deivid-rodriguez deivid-rodriguez merged commit 4064fb6 into rubygems:master Sep 27, 2023
92 checks passed
deivid-rodriguez added a commit that referenced this pull request Oct 13, 2023
…ive-path

Avoid error reporting relative path when validating frozen

(cherry picked from commit 4064fb6)
deivid-rodriguez added a commit that referenced this pull request Oct 13, 2023
…ive-path

Avoid error reporting relative path when validating frozen

(cherry picked from commit 4064fb6)
deivid-rodriguez added a commit that referenced this pull request Oct 13, 2023
…ive-path

Avoid error reporting relative path when validating frozen

(cherry picked from commit 4064fb6)
deivid-rodriguez added a commit that referenced this pull request Oct 16, 2023
…ive-path

Avoid error reporting relative path when validating frozen

(cherry picked from commit 4064fb6)
shinokaro added a commit to Largo/ocran that referenced this pull request May 7, 2024
In this commit, we update to 2.4.22, which is the final version of 2.4. Versions 2.4.20 and below fail the CI tests due to a bug (rubygems/rubygems#5128). This bug was fixed in 2.4.21. We will not switch to Bundler 2.5 as OCRAN supports Ruby 2.x.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants