jdx/mise · error · RuntimeError
could not infer formula version; add an explicit version…
Error message
could not infer formula version; add an explicit version declaration
What it means
Thrown by mise's brew tap formula metadata reader (src/system/packages/brew/tap_formula_metadata.rb). The Ruby helper evals a Homebrew formula file, extracts the Formula subclass, and needs a stable version string for the metadata manifest. When neither an explicit `version` declaration in the formula nor a URL-based inference (via inferred_version on source_url) yields a non-empty version, it raises this error instead of writing metadata with an empty 'stable' version.
Solutions
- Add an explicit `version "X.Y.Z"` declaration to the formula file near the url clause.
- Change the formula's url to a versioned/tagged archive URL (e.g. https://.../archive/v1.2.3.tar.gz) so inferred_version can parse the version.
- If the formula intentionally tracks HEAD, pin it to a specific commit/ref archive URL and declare the version.
Example fix
# before formula "mytool" do url "https://github.com/example/mytool/archive/refs/heads/main.tar.gz" end # after formula "mytool" do url "https://github.com/example/mytool/archive/refs/heads/main.tar.gz" version "1.4.2" end
Defensive patterns
Strategy: validation
Validate before calling
# before generating metadata, check the formula declares a version or has an inferrable URL
formula = File.read(path)
abort "formula #{path} needs an explicit version" if formula.include?('refs/heads/main.tar.gz') && !formula.match?(/^\s*version\s+/) Prevention
- Always declare an explicit `version` in custom tap formulas whose URL is not a tagged archive.
- Prefer versioned archive URLs over branch/HEAD tarballs in formulas.
- Lint custom taps with a check for version declarations on rolling URLs.
When it happens
Trigger: Running the metadata extraction script against a formula whose source_url has no derivable version (e.g. a branch/reference tarball like `:branch => "main"` or an untagged git HEAD) and which does not declare an explicit `version` clause.
Common situations: Custom/private taps with formulas pointing at rolling-release git URLs, formulas regenerated after upstream moved from tagged releases to HEAD tarballs, or hand-written formulas missing `version "1.2.3"` after the URL changed so Homebrew's version heuristics no longer match.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- formula declares a DATA patch but has no __END__ section
- formula has no stable sha256
- formula has no stable URL
- inreplace in # made no substitutions — the formula may need…
- no Formula subclass found
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/c5ee82361df77b6a.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/packages/brew/tap_formula_metadata.rb:240
def keg_only_reason_metadata(klass)
reason = klass.keg_only_reason_value
return nil if reason.nil?
{ "reason" => reason.is_a?(Symbol) ? reason.inspect : reason.to_s }
end
def inferred_version(url)
basename = File.basename(url.to_s).sub(/\.(tar\.(gz|xz|bz2|zst)|tgz|txz|zip|gz)\z/i, "")
match = basename.match(/(?:^|[-_v])([0-9]+(?:\.[0-9A-Za-z]+)+(?:[-_.][0-9A-Za-z]+)*)/)
match && match[1]
end
eval(STDIN.read.force_encoding("UTF-8"), TOPLEVEL_BINDING, FORMULA_FILE, 1)
klass = Formula.instance_variable_get(:@subclass)
raise "no Formula subclass found" unless klass
raise "formula has no stable URL" if klass.source_url.to_s.empty?
raise "formula has no stable sha256" if klass.source_sha256.to_s.empty?
version = (klass.explicit_version || inferred_version(klass.source_url)).to_s
raise "could not infer formula version; add an explicit version declaration" if version.to_s.empty?
metadata = {
"name" => FORMULA_NAME,
"tap" => ENV.fetch("MISE_BREW_TAP"),
"versions" => { "stable" => version },
"revision" => klass.revision_value || 0,
"keg_only" => klass.keg_only_value || false,
"keg_only_reason" => keg_only_reason_metadata(klass),
"dependencies" => klass.runtime_dependencies || [],
"build_dependencies" => klass.build_dependencies || [],
"bottle" => {},
"urls" => { "stable" => { "url" => klass.source_url, "checksum" => klass.source_sha256 } },
"ruby_source_path" => ENV.fetch("MISE_BREW_SOURCE_PATH"),
"ruby_source_checksum" => { "sha256" => ENV.fetch("MISE_BREW_SOURCE_CHECKSUM") },
"tap_git_head" => ENV.fetch("MISE_BREW_TAP_COMMIT")
}
puts JSON.generate(metadata)
View on GitHub (pinned to 533346cc37)