Skip to content

Breaking change on GemfileNotFound behavior on 4.0.1 #9182

@roger-zhangg

Description

@roger-zhangg

Description

In Bundler 4.0.1, a breaking change was introduced in how GemfileNotFound errors are handled. Previously, when a Gemfile was not found, Bundler would exit with status code 10. However, in 4.0.1, if the invoke_other_command("cli_help") call fails during the error handling, a different exit code is returned due to the NoMethodError, breaking the expected behavior.

Current Behavior

When running bundle commands without a Gemfile present:

GemfileNotFound error is caught
invoke_other_command("cli_help") is called
If cli_help fails (as shown in the error log with NoMethodError), the original GemfileNotFound error is thrown later and its exit code 10 are lost
Instead, a NoMethodError is raised first with a different exit code

Expected Behavior

Even if the help command fails, Bundler should maintain the original GemfileNotFound error and exit code 10 to preserve backward compatibility and expected behavior.

Error Log

NoMethodError: undefined method `[]' for nil:NilClass
  C:/hostedtoolcache/windows/Ruby/3.2.9/x64/lib/ruby/gems/3.2.0/gems/bundler-4.0.1/lib/bundler/cli.rb:107:in `block in cli_help'
  ...

Relevant Code

#9164

https://github.com/eregon/rubygems/blob/979dada8f39999191f23cd0ded6191aff57e093f/bundler/lib/bundler/cli.rb#L293-L295

Environment

Bundler: 4.0.1
Ruby: 3.2.9p265
Platform: x64-mingw-ucrt

Suggested Fix

Consider one of these approaches:

Ensure cli_help doesn't fail when handling GemfileNotFound
Wrap the invoke_other_command in a begin/rescue block to preserve the original error
Remove the help command invocation for this specific error case

This is a breaking change as it affects tools and scripts that rely on the exit code 10 for GemfileNotFound errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions