ruby / ruby/rubygems

Bundler-command executables result in "Errno::ENOENT: No such file or directory" for executables in local working directory

Open
#9,479 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bundler
Dominant language
Ruby
Stars
4k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
81

Description

Describe the problem as clearly as you can

When attempting to run a bundler-{x} executable using a bundle {x} when the x executable is in the local directory, Bundler returns an Errno::ENOENT: No such file or directory error

Did you try upgrading rubygems & bundler?

Yes

Post steps to reproduce the problem

I found this while trying to setup typo aliases (tbqh I accidentally type bundel isntall or some variety of it when in a hurry fairly often and got annoyed). The repro is quite simple:

> bundle test-repro
Could not find command "test-repro".

> echo "which ruby" > bundler-test-repro
> chmod +x bundler-test-repro
> bundle test-repro

I believe this is an issue in CLI::handle_no_command_error, specifically in Bundler::which:
https://github.com/ruby/rubygems/blob/3e3addb8d222d23ac46ca3b1959b29b7b93b04db/bundler/lib/bundler.rb#L479-L491

The first line, executable_path = find_executable(executable), returns the executable name without any path if the executable is present in the local working directory. Lower in that method, while looping through the PATH environment variable entries, the method calls File.expand_path first, which results in full file paths being returned. Replacing find_executable(executable) with find_executable(File.expand_path(executable)) seems to fix the issue:

irb(main):001> require 'bundler'
=> true
irb(main):002> command_path = Bundler.find_executable('bundler-test-repro')
=> "bundler-test-repro"
irb(main):003> Kernel.exec(command_path, *ARGV[1..-1])
(irb):4:in 'Kernel.exec': No such file or directory - bundler-test-repro (Errno::ENOENT)
	from (irb):4:in '<main>'
	from <internal:kernel>:168:in 'Kernel#loop'
	from /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/irb-1.17.0/exe/irb:9:in '<top (required)>'
	from /Users/josh.wise/.rbenv/versions/3.4.9/bin/irb:25:in 'Kernel#load'
	from /Users/josh.wise/.rbenv/versions/3.4.9/bin/irb:25:in '<main>'
irb(main):004> command_path = Bundler.find_executable(File.expand_path('bundler-test-repro'))
=> "/Users/josh.wise/notarize/notarize-api/bundler-test-repro"
irb(main):005> Kernel.exec(command_path, *ARGV[1..-1])
/Users/josh.wise/.rbenv/versions/3.4.9/bin/ruby
Which command did you run?

Any custom bundler-{x} command that's defined in the local working directory

What were you expecting to happen?

The custom bundler-{x} command should run as expected as per the man page:

PLUGINS
       When running a command that isn´t listed in PRIMARY COMMANDS or UTILITIES, Bundler will try to find an executable on your path named
       bundler-<command> and execute it, passing down any extra arguments to it.
What happened instead?

--- ERROR REPORT TEMPLATE -------------------------------------------------------

Errno::ENOENT: No such file or directory - bundler-test-repro
  /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/cli.rb:194:in 'Kernel.exec'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/cli.rb:194:in 'Bundler::CLI.handle_no_command_error'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/vendor/thor/lib/thor/command.rb:32:in 'Bundler::Thor::Command#run'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/vendor/thor/lib/thor/command.rb:144:in 'Bundler::Thor::DynamicCommand#run'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in 'Bundler::Thor::Invocation#invoke_command'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/vendor/thor/lib/thor.rb:538:in 'Bundler::Thor.dispatch'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/cli.rb:35:in 'Bundler::CLI.dispatch'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/vendor/thor/lib/thor/base.rb:584:in 'Bundler::Thor::Base::ClassMethods#start'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/cli.rb:29:in 'Bundler::CLI.start'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/exe/bundle:28:in 'block in <top (required)>'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/lib/bundler/friendly_errors.rb:118:in 'Bundler.with_friendly_errors'
          /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/bundler-4.0.8/exe/bundle:20:in '<top (required)>'
          /Users/josh.wise/.rbenv/versions/3.4.9/bin/bundle:25:in 'Kernel#load'
          /Users/josh.wise/.rbenv/versions/3.4.9/bin/bundle:25:in '<main>'

Environment

Bundler       4.0.8
  Platforms   ruby, arm64-darwin-25
Ruby          3.4.9p82 (2026-03-11 revision 76cca827ab52ab1d346a728f068d5b8da3e2952b) [arm64-darwin-25]
  Full Path   /Users/josh.wise/.rbenv/versions/3.4.9/bin/ruby
  Config Dir  /Users/josh.wise/.rbenv/versions/3.4.9/etc
RubyGems      3.6.9
  Gem Home    /Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0
  Gem Path    /Users/josh.wise/.local/share/gem/ruby/3.4.0:/Users/josh.wise/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0
  User Home   /Users/josh.wise
  User Path   /Users/josh.wise/.local/share/gem/ruby/3.4.0
  Bin Dir     /Users/josh.wise/.rbenv/versions/3.4.9/bin
Tools
  Git         2.50.1 (Apple Git-155)
  RVM         not installed
  rbenv       rbenv 1.3.2
  chruby      not installed

Bundler Build Metadata

Timestamp  2026-03-11
Git SHA    1a32b76b73

Bundler settings

gems.contribsys.com
  Set for your local app (/Users/josh.wise/notarize/notarize-api/.bundle/config): "daf018b1:[REDACTED]"
gems.graphql.pro
  Set for your local app (/Users/josh.wise/notarize/notarize-api/.bundle/config): "gql_281_8447f019352:[REDACTED]"
with
  Set for your local app (/Users/josh.wise/notarize/notarize-api/.bundle/config): [:debug]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Bundler::CLI.handle_no_command_error in bundler/lib/bundler/cli.rb and Bundler.find_executable in bundler/lib/bundler.rb, then reproduce the issue with a local executable named bundler-test-repro. Done means a local bundler-{x} executable is resolved with a usable path and runs through bundle {x} without Errno::ENOENT.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.