{"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":267,"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":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/jdx/mise/blob/9dcfcaa0dc8747a2577d3270b69bb9d8313b2807/src/cli/generate/tool_stub.rs#L249-L285","documentation":"`mise generate tool-stub` is append/extend-only for existing stub files: when the output file already exists and contains a `version` key, regenerating with a different --version is rejected. The tool reuses the existing TOML document so platform URLs can be added incrementally; changing the version would silently re-point every existing platform URL/checksum to the wrong release.","triggerScenarios":"Running generate a second time on the same output file with `--version 2.0.0` when the stub already says `version = \"1.0.0\"`; CI pipelines that pass a bumped version variable into a stub file kept in the repo.","commonSituations":"Maintaining a checked-in stub across releases; incrementally adding platforms with `--platform-url` (works fine) but also bumping --version in the same invocation (fails).","solutions":["Regenerate from scratch: delete (or rename) the existing stub file and run generate again with the new --version","Edit the stub file by hand and change the `version` line, then run `mise generate tool-stub <file> --lock` or `--fetch` to refresh checksums/URLs","Write the new version to a different output path and keep both stubs"],"exampleFix":"# before (stub file has version = \"1.0.0\")\nmise generate tool-stub ./ctl --version 2.0.0 --url https://.../v2.0.0/ctl.tar.gz\n# after\nrm ./ctl && mise generate tool-stub ./ctl --version 2.0.0 --url https://.../v2.0.0/ctl.tar.gz","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\nstub=./ctl\nif [[ -f \"$stub\" ]]; then\n  cur=$(grep -oP '^version\\s*=\\s*\"\\K[^\"]+' \"$stub\")\n  if [[ \"$cur\" && \"$cur\" != \"$NEW_VER\" ]]; then\n    echo \"stub is version $cur; removing before regenerating at $NEW_VER\" >&2\n    rm \"$stub\"\n  fi\nfi\nmise generate tool-stub \"$stub\" --version \"$NEW_VER\" --url \"$url\"","typeGuard":null,"tryCatchPattern":"if ! mise generate tool-stub ./ctl --version \"$v\" ... 2>err.log; then grep -q 'Cannot change version' err.log && { rm ./ctl; mise generate tool-stub ./ctl --version \"$v\" ...; }; fi","preventionTips":["Treat stub version as immutable per file; delete or rename the stub when bumping versions","In release automation, generate to a fresh path per release tag"],"tags":["cli","tool-stub","version-conflict","mise"],"backgroundTag":"version-mismatch","analyzedSha":"9dcfcaa0dc8747a2577d3270b69bb9d8313b2807","analyzedAt":"2026-08-17T14:28:50.624Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}