Skip to content

Conversation

@Fryguy
Copy link
Contributor

@Fryguy Fryguy commented Oct 21, 2025

In my specific case, my Gemfile has a eval_gemfile that pulls in another Gemfile in a subdirectory that hasn't been generated yet (similar to an non-updated git submodule). This causes rubocop to blow up with

$ rubocop
No such file or directory @ rb_sysopen - /Users/jfrey/dev/my_app/my_subdir/Gemfile
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler.rb:524:in `initialize'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler.rb:524:in `open'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler.rb:524:in `block in read_file'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/shared_helpers.rb:105:in `filesystem_access'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler.rb:523:in `read_file'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/dsl.rb:46:in `block in eval_gemfile'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/dsl.rb:314:in `with_gemfile'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/dsl.rb:45:in `eval_gemfile'
/Users/jfrey/dev/my_app/Gemfile:12:in `block in eval_gemfile'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/dsl.rb:47:in `instance_eval'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/dsl.rb:47:in `block in eval_gemfile'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/dsl.rb:314:in `with_gemfile'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/dsl.rb:45:in `eval_gemfile'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/dsl.rb:12:in `evaluate'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler/definition.rb:37:in `build'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler.rb:236:in `definition'
/Users/jfrey/.gem/ruby/3.3.9/gems/bundler-2.7.1/lib/bundler.rb:218:in `load'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_loader_resolver.rb:296:in `gem_config_path'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_loader_resolver.rb:84:in `block (2 levels) in resolve_inheritance_from_gems'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_loader_resolver.rb:82:in `reverse_each'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_loader_resolver.rb:82:in `block in resolve_inheritance_from_gems'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_loader_resolver.rb:76:in `each_pair'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_loader_resolver.rb:76:in `resolve_inheritance_from_gems'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_loader.rb:58:in `load_file'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_loader.rb:120:in `configuration_from_file'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_store.rb:73:in `for_dir'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/config_store.rb:52:in `for_pwd'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/cli.rb:155:in `parallel_by_default!'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/cli.rb:51:in `block in run'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/cli.rb:87:in `profile_if_needed'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/lib/rubocop/cli.rb:45:in `run'
/Users/jfrey/.gem/ruby/3.3.9/gems/rubocop-1.81.6/exe/rubocop:15:in `<top (required)>'
/Users/jfrey/.rubies/ruby-3.3.9/lib/ruby/site_ruby/3.3.0/rubygems.rb:319:in `load'
/Users/jfrey/.rubies/ruby-3.3.9/lib/ruby/site_ruby/3.3.0/rubygems.rb:319:in `activate_and_load_bin_path'
/Users/jfrey/.gem/ruby/3.3.9/bin/rubocop:25:in `<main>'

After this change, everything works fine, because the code falls back to the system installed rubocop

In general, when the Gemfile fails to load for any reason, we want to fallback to try loading from the system gems. (This is is effectively an extension of the handlers in #12976 and #12991)

A non-specific issue could be something like eval_gemfile failing when a submodule that includes the requisite file has not yet been updated.

This commit changes the rescue to the generic StandardError, which subsumes the Bundler errors, and handles other errors as well.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@Fryguy Fryguy force-pushed the handle_gemfile_errors branch from 8a47fdd to b6b33e6 Compare October 21, 2025 21:46
@koic
Copy link
Member

koic commented Oct 22, 2025

This looks good to me. Can you add a changelog entry?

Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@koic
Copy link
Member

koic commented Oct 22, 2025

Can you squash your commits into one?

In general, when the Gemfile fails to load for any reason, we want to
fallback to try loading from the system gems.

A non-specific issue could be something like eval_gemfile failing when
a submodule that includes the requisite file has not yet been updated.

This commit changes the rescue to the generic StandardError, which
subsumes the Bundler errors, and handles other errors as well.
@Fryguy Fryguy force-pushed the handle_gemfile_errors branch from a3f6079 to 354f3a7 Compare October 22, 2025 13:19
@Fryguy
Copy link
Contributor Author

Fryguy commented Oct 22, 2025

Done - I messed up the changelog entry the first time, so this update should have it correct now

@koic
Copy link
Member

koic commented Oct 22, 2025

Thanks!

@koic koic merged commit 1b53b1c into rubocop:master Oct 22, 2025
22 checks passed
@Fryguy Fryguy deleted the handle_gemfile_errors branch October 22, 2025 15:08
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.

2 participants