{"record":{"id":"68c559d4b896c4a5","repo":"jdx/mise","slug":"cannot-change-version-of-existing-tool-stub-from","errorCode":null,"errorMessage":"Cannot change version of existing tool stub from {} to {}","messagePattern":"Cannot change version of existing tool stub from (.+?) to (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/generate/tool_stub.rs","lineNumber":282,"sourceCode":"            bail!(\"Either --url or --platform-url must be specified\");\n        }\n\n        // Read existing file if it exists\n        let (existing_content, mut doc) = if self.output.exists() {\n            let content = file::read_to_string(&self.output)?;\n            let toml_content = extract_toml_from_stub(&content);\n\n            let document = toml_content.parse::<DocumentMut>()?;\n            (Some(content), document)\n        } else {\n            (None, DocumentMut::new())\n        };\n\n        // If file exists but we're trying to set a different version, bail\n        if existing_content.is_some() && doc.get(\"version\").is_some() {\n            let existing_version = doc.get(\"version\").and_then(|v| v.as_str()).unwrap_or(\"\");\n            if existing_version != self.version {\n                bail!(\n                    \"Cannot change version of existing tool stub from {} to {}\",\n                    existing_version,\n                    self.version\n                );\n            }\n        }\n\n        // Set or update version only if it's not \"latest\" (which should be the default)\n        if self.version != \"latest\" {\n            doc[\"version\"] = toml_edit::value(&self.version);\n        }\n\n        // Get the stub filename (without path)\n        let stub_filename = self\n            .output\n            .file_stem()\n            .and_then(|s| s.to_str())\n            .unwrap_or(\"\");","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/cli/generate/tool_stub.rs#L264-L300","documentation":"If a tool stub file already exists at the output path and declares a `version`, `mise generate tool-stub` refuses to regenerate with a different `--version`. The stub's version is treated as immutable on regeneration to avoid silently changing what an existing stub pins; changing it requires removing the existing stub or matching the version.","triggerScenarios":"Running `mise generate tool-stub` with `--output` pointing at an existing stub file whose TOML `version` field differs from the `--version` argument (including when `--version` is absent and defaults to something else).","commonSituations":"Re-running generation after a tool released a new version; CI regenerates stubs with a newer pinned version; user forgot the stub already exists with an older pinned version.","solutions":["Pass `--version` matching the existing stub's version, or omit regeneration","Delete the existing stub file and regenerate with the new version","Manually edit the `version` field in the stub TOML if intentional"],"exampleFix":"// before: existing stub has version = \"1.0.0\"\nmise generate tool-stub --output rg.toml --url ... --version 2.0.0   # bails\n// after\ndelete rg.toml\nmise generate tool-stub --output rg.toml --url ... --version 2.0.0","handlingStrategy":"try-catch","validationCode":"if (fs.existsSync(outFile)) {\n  const existing = TOML.parse(fs.readFileSync(outFile, 'utf8'));\n  if (existing.version && wantedVersion && existing.version !== wantedVersion) {\n    throw new Error(`delete or align stub: existing ${existing.version} vs wanted ${wantedVersion}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await exec(`mise generate tool-stub --output ${out} --version ${v} ...`);\n} catch (e) {\n  if (String(e).includes('Cannot change version')) {\n    fs.rmSync(out);\n    await exec(`mise generate tool-stub --output ${out} --version ${v} ...`);\n  }\n}","preventionTips":["Read the existing stub's version before regenerating","Treat stub files as immutable pins; delete to re-pin","Automate version bumps by deleting the stub first in CI"],"tags":["tool-stub","version-conflict","cli"],"backgroundTag":"conflicting-config-options","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"}