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

regression in 1.63.1 -- "Could not locate Gemfile" #12846

Closed
asottile opened this issue Apr 16, 2024 · 3 comments · Fixed by #12847
Closed

regression in 1.63.1 -- "Could not locate Gemfile" #12846

asottile opened this issue Apr 16, 2024 · 3 comments · Fixed by #12847

Comments

@asottile
Copy link
Contributor

appears to be a regression of some very old issues #9148 and #6939

a sample ruby file (t.rb)

# frozen_string_literal: true

puts 'hello world'

install a copy of rubocop 1.63.0 and 1.63.1:

GEM_HOME=$PWD/gems-old gem install rubocop --version 1.63.0 --no-document
GEM_HOME=$PWD/gems-new gem install rubocop --version 1.63.1 --no-document

Expected behavior

on 1.63.0 I get:

$ GEM_HOME=$PWD/gems-old gems-old/bin/rubocop t.rb; echo -e "---\n$?"
Inspecting 1 file
.

1 file inspected, no offenses detected
---
0

Actual behavior

on 1.63.1 I get:

$ GEM_HOME=$PWD/gems-new gems-new/bin/rubocop t.rb; echo -e "---\n$?"
Inspecting 1 file
.

1 file inspected, no offenses detected
Could not locate Gemfile
/usr/lib/ruby/3.0.0/bundler/shared_helpers.rb:21:in `default_gemfile'
/usr/lib/ruby/3.0.0/bundler/shared_helpers.rb:26:in `default_lockfile'
/usr/lib/ruby/3.0.0/bundler.rb:453:in `default_lockfile'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/lockfile.rb:16:in `initialize'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli/command/suggest_extensions.rb:108:in `new'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli/command/suggest_extensions.rb:108:in `lockfile'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli/command/suggest_extensions.rb:74:in `all_extensions'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli/command/suggest_extensions.rb:96:in `not_installed_extensions'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli/command/suggest_extensions.rb:88:in `extensions'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli/command/suggest_extensions.rb:18:in `run'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli/command.rb:11:in `run'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli/environment.rb:18:in `run'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli.rb:118:in `run_command'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli.rb:130:in `suggest_extensions'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli.rb:125:in `block in execute_runners'
<internal:kernel>:90:in `tap'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli.rb:125:in `execute_runners'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli.rb:51:in `block in run'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli.rb:77:in `profile_if_needed'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/lib/rubocop/cli.rb:43:in `run'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/exe/rubocop:19:in `block in <top (required)>'
/usr/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
/tmp/y/z/gems-new/gems/rubocop-1.63.1/exe/rubocop:19:in `<top (required)>'
gems-new/bin/rubocop:25:in `load'
gems-new/bin/rubocop:25:in `<main>'
---
2

annoyingly, --debug causes it to no longer crash:

$ GEM_HOME=$PWD/gems-new gems-new/bin/rubocop t.rb --debug; echo -e "---\n$?"
For /tmp/y/z: Default configuration from /tmp/y/z/gems-new/gems/rubocop-1.63.1/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /tmp/y/z/t.rb
Loading cache from /home/asottile/.cache/rubocop_cache/6d1654be5b0207c1e9d80e4f40bb1c9d8d020976/6d7a3b621ca1730e04accd938619e4bdab66cfb1/cde7fc7a75eb728f1543d2d26c72b8a2cff94be8
.

1 file inspected, no offenses detected
Finished in 0.21053658401069697 seconds
---
0

Steps to reproduce the problem

see above!

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

$ GEM_HOME=$PWD/gems-new gems-new/bin/rubocop -V
1.63.1 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.0.2) [x86_64-linux-gnu]
@asottile
Copy link
Contributor Author

#12826 appears to be the cause -- bisected to b0c508a and reverting it makes the regression goes away -- cc @bbatsov @amomchilov

koic added a commit to koic/rubocop that referenced this issue Apr 16, 2024
Fixes rubocop#12846.

This PR fixes an error for `RuboCop::Lockfile`
when there is no Bundler environment.

From a performance perspective as well, resolving through `require 'bundler'` is not optimal.
This PR ensures that the necessary `Bundler::LockfileParser` exists as a constant.
This approach reduces unnecessary loading caused by `require 'bundler'` and
ensures the presence of the essential `Bundler::LockfileParser`.
@koic
Copy link
Member

koic commented Apr 16, 2024

Thank you for the feedback. I've opened #12847 to solve the issue.

bbatsov pushed a commit that referenced this issue Apr 16, 2024
Fixes #12846.

This PR fixes an error for `RuboCop::Lockfile`
when there is no Bundler environment.

From a performance perspective as well, resolving through `require 'bundler'` is not optimal.
This PR ensures that the necessary `Bundler::LockfileParser` exists as a constant.
This approach reduces unnecessary loading caused by `require 'bundler'` and
ensures the presence of the essential `Bundler::LockfileParser`.
@amomchilov
Copy link
Contributor

Ah so the issue here isn't the require 'bundler'. That actually succeeded, even in folders without a Gemfile(.lock).

This error was caused by Bundler::GemfileNotFound being raised here:

lockfile_path ||= defined?(Bundler) ? Bundler.default_lockfile : nil

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 a pull request may close this issue.

3 participants