ruby/ruby · error · InvalidOption

Extensions can now be generated using C or Rust, so `--ext`

Error message

Extensions can now be generated using C or Rust, so `--ext` with no arguments has been removed. Please select a language, e.g. `--ext=rust` to generate a Rust extension.

What it means

`bundle gem --ext` with no language argument used to default to a C extension. Extensions can now be C, Rust, or Go, so a bare `--ext` (or one followed by a value not in EXTENSIONS) raises Bundler::InvalidOption from Bundler::CLI.check_invalid_ext_option (lib/bundler/cli.rb:719). The language must be named explicitly.

Source

Thrown at lib/bundler/cli.rb:719

        if exec_used + help_used == 1
          %w[help exec]
        else
          args
        end
      elsif help_used
        args = args.dup
        args.delete_at(help_used)
        ["help", command || args].flatten.compact
      else
        args
      end
    end

    def self.check_invalid_ext_option(arguments)
      # when invalid version of `--ext` is called
      if invalid_ext_value?(arguments)
        removed_message = "Extensions can now be generated using C or Rust, so `--ext` with no arguments has been removed. Please select a language, e.g. `--ext=rust` to generate a Rust extension."
        raise InvalidOption, removed_message
      end
    end

    def self.invalid_ext_value?(arguments)
      index = arguments.index("--ext")
      next_argument = arguments[index + 1]

      # it is ok when --ext is followed with valid extension value
      # for example `bundle gem hello --ext c`
      return false if EXTENSIONS.include?(next_argument)

      # invalid call when --ext is called with no value in last position
      # for example `bundle gem hello_gem --ext`
      return true if next_argument.nil?

      # invalid call when --ext is followed by other parameter
      # for example `bundle gem --ext --no-ci hello_gem`
      return true if next_argument.start_with?("-")

View on GitHub (pinned to 0e5b888e1c)

Solutions

  1. Pass the language explicitly: `--ext=c`, `--ext=rust`, or `--ext=go`
  2. Double-check the value's spelling — only c, rust, and go are valid
  3. Update generators that emit a bare --ext

Example fix

# before
$ bundle gem mygem --ext

# after
$ bundle gem mygem --ext=rust
Defensive patterns

Strategy: validation

Validate before calling

EXTS = %w[c rust go].freeze
i = args.index('--ext')
if i && !EXTS.include?(args[i + 1])
  abort 'pass a language explicitly: --ext=c, --ext=rust, or --ext=go'
end
system('bundle', 'gem', name, *args)

Try / catch

begin
  Bundler::CLI.start(['gem', name, *args])
rescue Bundler::InvalidOption
  raise unless args.include?('--ext')
  lang = ask('extension language (c/rust/go): ')
  args.delete('--ext')
  Bundler::CLI.start(['gem', name, "--ext=#{lang}", *args])
end

Prevention

When it happens

Trigger: `bundle gem mygem --ext` as the last argument, or `--ext` followed by a value not in EXTENSIONS ("c", "rust", "go") — e.g. `--ext cpp`, or `--ext` immediately followed by another flag.

Common situations: Old tutorials and scaffolders using bundler 1.x/early 2.x bare `--ext`; developers wanting a Rust native extension for the first time.

Related errors


AI-assisted analysis of ruby/ruby@0e5b888e1c (2026-08-21). Data as JSON: /api/errors/6128c1d9a0dc9e78. Report an issue: GitHub.