{"record":{"id":"c5ee82361df77b6a","repo":"jdx/mise","slug":"could-not-infer-formula-version-add-an-explicit-v","errorCode":null,"errorMessage":"could not infer formula version; add an explicit version declaration","messagePattern":"could not infer formula version; add an explicit version declaration","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/tap_formula_metadata.rb","lineNumber":240,"sourceCode":"def keg_only_reason_metadata(klass)\n  reason = klass.keg_only_reason_value\n  return nil if reason.nil?\n  { \"reason\" => reason.is_a?(Symbol) ? reason.inspect : reason.to_s }\nend\n\ndef inferred_version(url)\n  basename = File.basename(url.to_s).sub(/\\.(tar\\.(gz|xz|bz2|zst)|tgz|txz|zip|gz)\\z/i, \"\")\n  match = basename.match(/(?:^|[-_v])([0-9]+(?:\\.[0-9A-Za-z]+)+(?:[-_.][0-9A-Za-z]+)*)/)\n  match && match[1]\nend\n\neval(STDIN.read.force_encoding(\"UTF-8\"), TOPLEVEL_BINDING, FORMULA_FILE, 1)\nklass = Formula.instance_variable_get(:@subclass)\nraise \"no Formula subclass found\" unless klass\nraise \"formula has no stable URL\" if klass.source_url.to_s.empty?\nraise \"formula has no stable sha256\" if klass.source_sha256.to_s.empty?\nversion = (klass.explicit_version || inferred_version(klass.source_url)).to_s\nraise \"could not infer formula version; add an explicit version declaration\" if version.to_s.empty?\n\nmetadata = {\n  \"name\" => FORMULA_NAME,\n  \"tap\" => ENV.fetch(\"MISE_BREW_TAP\"),\n  \"versions\" => { \"stable\" => version },\n  \"revision\" => klass.revision_value || 0,\n  \"keg_only\" => klass.keg_only_value || false,\n  \"keg_only_reason\" => keg_only_reason_metadata(klass),\n  \"dependencies\" => klass.runtime_dependencies || [],\n  \"build_dependencies\" => klass.build_dependencies || [],\n  \"bottle\" => {},\n  \"urls\" => { \"stable\" => { \"url\" => klass.source_url, \"checksum\" => klass.source_sha256 } },\n  \"ruby_source_path\" => ENV.fetch(\"MISE_BREW_SOURCE_PATH\"),\n  \"ruby_source_checksum\" => { \"sha256\" => ENV.fetch(\"MISE_BREW_SOURCE_CHECKSUM\") },\n  \"tap_git_head\" => ENV.fetch(\"MISE_BREW_TAP_COMMIT\")\n}\nputs JSON.generate(metadata)\n","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/tap_formula_metadata.rb#L222-L258","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nformula \"mytool\" do\n  url \"https://github.com/example/mytool/archive/refs/heads/main.tar.gz\"\nend\n# after\nformula \"mytool\" do\n  url \"https://github.com/example/mytool/archive/refs/heads/main.tar.gz\"\n  version \"1.4.2\"\nend","handlingStrategy":"validation","validationCode":"# before generating metadata, check the formula declares a version or has an inferrable URL\nformula = File.read(path)\nabort \"formula #{path} needs an explicit version\" if formula.include?('refs/heads/main.tar.gz') && !formula.match?(/^\\s*version\\s+/)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["homebrew","formula","version-inference","ruby"],"backgroundTag":"missing-required-config-field","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}