ruby/ruby · error · InvalidOption
Cannot specify `--path` option without a value
Error message
Cannot specify `--path` option without a value
What it means
CLI::Open (lib/bundler/cli/open.rb:13) implements `bundle open GEM --path <relative-path>` to open a subdirectory of the gem in your editor. The constructor keeps options[:path] when non-nil, and run raises Bundler::InvalidOption if that value is present but empty — an empty string would produce a meaningless File.join and an editor launched at an invalid path.
Source
Thrown at lib/bundler/cli/open.rb:13
# frozen_string_literal: true
module Bundler
class CLI::Open
attr_reader :options, :name, :path
def initialize(options, name)
@options = options
@name = name
@path = options[:path] unless options[:path].nil?
end
def run
raise InvalidOption, "Cannot specify `--path` option without a value" if !@path.nil? && @path.empty?
editor = [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? }
return Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR") unless editor
return unless spec = Bundler::CLI::Common.select_spec(name, :regex_match)
if spec.default_gem?
Bundler.ui.info "Unable to open #{name} because it's a default gem, so the directory it would normally be installed to does not exist."
else
root_path = spec.full_gem_path
command = editor_command(editor) << File.join([root_path, path].compact)
Bundler.with_original_env do
system(*command, { chdir: root_path })
end || Bundler.ui.info("Could not run '#{command.join(" ")}'")
end
end
def editor_command(editor)
# On Windows an editor is often configured with a full path such as
# C:\Program Files\Microsoft VS Code\Code.exe, which shell splitting
# would corrupt. Take a value that names an existing file as aView on GitHub (pinned to 0e5b888e1c)
Solutions
- Pass a real relative path inside the gem: `bundle open rack --path lib/rack`
- If the value is optional in your script, omit the --path flag entirely when it is empty
- Default the variable: `--path "${SUBDIR:-lib}"`
Example fix
# before $ bundle open nokogiri --path "" # => Cannot specify `--path` option without a value # after $ bundle open nokogiri --path ext/nokogiri
Defensive patterns
Strategy: validation
Validate before calling
subpath = ENV['GEM_SUBPATH'] args = %w[bundle open mygem] args += ['--path', subpath] if subpath && !subpath.strip.empty? system(*args)
Type guard
def usable_open_path?(value) !value.nil? && !value.empty? end
Try / catch
begin Bundler::CLI::Open.new(options, name).run rescue Bundler::InvalidOption => e warn e.message exit 1 end
Prevention
- Only pass --path when the variable is non-empty
- Default subpaths in wrappers: ${SUBPATH:-lib}
When it happens
Trigger: `bundle open rack --path ''` or `--path ""`, typically when the value comes from a shell variable that is set but empty (e.g. $MY_GEM_SUBDIR unset with set -u style quoting producing "").
Common situations: Scripts parameterizing the subpath with a variable that is occasionally empty; CI env vars defined as blank strings; a trailing `--path` with an accidentally empty quoted argument.
Related errors
- Provide only one of the following options: #{patch_level.joi
- The options #{scopes.join " and "} were specified. Please on
- RubyGems doesn't know about trust policy '#{trust_policy}'.
- The `--only-group` and `--without-group` options cannot be u
- The `--name-only` and `--paths` options cannot be used toget
AI-assisted analysis of ruby/ruby@0e5b888e1c (2026-08-21).
Data as JSON: /api/errors/b3c755ad72091a02.
Report an issue: GitHub.