jdx/mise · error

ruby-build version regex

Error message

ruby-build version regex

What it means

mise panics with 'ruby-build version regex' in `ruby_build_version` when the output of `ruby-build --version` does not match `^ruby-build ([0-9.]+)`. The regex expects the first line to start with 'ruby-build ' followed by a dotted numeric version; any other output (localization, warnings, prefix text, or a changed upstream format) leaves `captures` as `None` and the expect panics.

Source

Thrown at src/plugins/core/ruby.rs:275

                .with_pr(pr)
                .arg("install")
                .envs(config.env().await?)
                .env_values(tv.install_env());
            match package.split_once(' ') {
                Some((name, "--pre")) => cmd = cmd.arg(name).arg("--pre"),
                Some((name, version)) => cmd = cmd.arg(name).arg("--version").arg(version),
                None => cmd = cmd.arg(package),
            };
            cmd.env(&*PATH_KEY, plugins::core::path_env_with_tv_path(tv)?)
                .execute()?;
        }
        Ok(())
    }

    fn ruby_build_version(&self) -> Result<String> {
        let output = cmd!(self.ruby_build_bin(), "--version").read()?;
        let re = regex!(r"^ruby-build ([0-9.]+)");
        let caps = re.captures(&output).expect("ruby-build version regex");
        Ok(caps.get(1).unwrap().as_str().to_string())
    }

    async fn latest_ruby_build_version(&self) -> Result<String> {
        let release: GithubRelease = HTTP_FETCH
            .json("https://api.github.com/repos/rbenv/ruby-build/releases/latest")
            .await?;
        Ok(release.tag_name.trim_start_matches('v').to_string())
    }

    fn install_rubygems_hook(&self, tv: &ToolVersion) -> Result<()> {
        let site_ruby_path = tv.install_path().join("lib/ruby/site_ruby");
        let f = site_ruby_path.join("rubygems_plugin.rb");
        file::create_dir_all(site_ruby_path)?;
        file::write(f, include_str!("assets/rubygems_plugin.rb"))?;
        Ok(())
    }

View on GitHub (pinned to afd2eddd3a)

Solutions

  1. Update ruby-build to the latest release (`git -C ~/.rbenv/plugins/ruby-build pull` or package manager upgrade)
  2. Run `ruby-build --version` manually and check the output matches 'ruby-build <numbers>'
  3. Ensure the resolved `ruby_build_bin()` is the real ruby-build, not a shim or different tool shadowing it on PATH
  4. Make the code return a descriptive error on regex mismatch instead of panicking

Example fix

// before
let caps = re.captures(&output).expect("ruby-build version regex");
Ok(caps.get(1).unwrap().as_str().to_string())
// after
let caps = re.captures(&output)
    .with_context(|| format!("unexpected ruby-build version output: {output}"))?;
Ok(caps.get(1).unwrap().as_str().to_string())
Defensive patterns

Strategy: validation

Validate before calling

let output = cmd!(bin, "--version").read()?; if !output.starts_with("ruby-build ") { bail!("unexpected ruby-build output: {output}"); }

Type guard

fn is_ruby_build_version_output(s: &str) -> bool { s.starts_with("ruby-build ") }

Try / catch

let Some(caps) = re.captures(&output) else { bail!("unexpected ruby-build --version output: {output}") };

Prevention

When it happens

Trigger: Running a ruby-build whose `--version` output changed format (new rbenv/ruby-build release), a shim/wrapper that prints extra text before the version line, stderr warnings interleaved into captured output, or a custom `ruby-build` binary (MISE_RUBY_BUILD_PATH or PATH shadowing) that is not the real ruby-build.

Common situations: Users with an old, forked, or Homebrew-patched ruby-build; rbenv's ruby-build printing deprecation notices; network/venv hooks emitting banners into the command output; environments where `ruby-build` resolves to a different tool with the same name.

Related errors


AI-assisted analysis of jdx/mise@afd2eddd3a (2026-09-09). Data as JSON: /api/errors/e9b8fa8a7896de8e. Report an issue: GitHub.