{"record":{"id":"c9a3260604aa320c","repo":"vectordotdev/vector","slug":"expected-package-version-expected-version-found-current","errorCode":null,"errorMessage":"expected package version {expected_version}, found {current_version}","messagePattern":"expected package version (.+?), found (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"vdev/src/commands/release/prepare.rs","lineNumber":297,"sourceCode":"    vrl_table.insert(\"version\", vrl_version.into());\n\n    Ok(doc.to_string())\n}\n\npub(super) fn update_vector_package_version(\n    cargo_toml_contents: &str,\n    expected_version: &str,\n    release_version: &str,\n) -> Result<String> {\n    let mut doc = cargo_toml_contents\n        .parse::<DocumentMut>()\n        .context(\"Failed to parse Cargo.toml\")?;\n    let current_version = doc[\"package\"][\"version\"]\n        .as_str()\n        .context(\"package.version should be a string\")?;\n\n    if current_version != expected_version {\n        bail!(\"expected package version {expected_version}, found {current_version}\");\n    }\n\n    doc[\"package\"][\"version\"] = toml_edit::value(release_version);\n    Ok(doc.to_string())\n}\n\nfn format_vrl_changelog_block(changelog: &str) -> String {\n    let double_tab = \"\\t\\t\";\n    let body = changelog\n        .lines()\n        .map(|line| {\n            let line = line.trim();\n            if line.starts_with('#') {\n                format!(\"{double_tab}#{line}\")\n            } else {\n                format!(\"{double_tab}{line}\")\n            }\n        })","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/vectordotdev/vector/blob/0d4ab78a4f0d9c9e5d03a50108a2ae4d2f4b2460/vdev/src/commands/release/prepare.rs#L279-L315","documentation":"`update_vector_package_version` parses the repo's Cargo.toml and only rewrites `package.version` if the current value exactly matches the expected (pre-release) version derived from the prepare step. A mismatch means the workspace's Cargo.toml was already bumped, manually edited, or is not at the version the release script expects, so it refuses to proceed rather than silently overwriting.","triggerScenarios":"Running `vdev release prepare` when Cargo.toml's `package.version` differs from `expected_version` — e.g. a previous prepare already bumped it, someone hand-edited Cargo.toml, or a merge changed the version field.","commonSituations":"Re-running prepare after a partial/failed run, preparing a hotfix while the master Cargo.toml was already bumped for the next minor, or a typo in the version argument.","solutions":["Check `package.version` in Cargo.toml and compare it with the version you passed to prepare.","If a previous run already bumped it, either reset Cargo.toml (`git checkout Cargo.toml`) and re-run, or continue from the already-prepared state.","If the version argument is wrong, re-run prepare with the version that matches the current Cargo.toml state.","Ensure the command runs from the repo root (prepare sets cwd via find_repo_root)."],"exampleFix":"// before: Cargo.toml already at 0.46.0, re-running prepare for 0.46.0\nexpected package version 0.46.0-dev.0, found 0.46.0\n// after: reset the workspace first\n$ git checkout Cargo.toml Cargo.lock\n$ vdev release prepare 0.46.0 0.12.0","handlingStrategy":"validation","validationCode":"# verify Cargo.toml is at the expected pre-release version first\ngrep -m1 '^version' Cargo.toml # compare with the version prepare expects","typeGuard":null,"tryCatchPattern":"match prepare_result {\n    Err(e) if e.to_string().contains(\"expected package version\") => {\n        eprintln!(\"Cargo.toml is at an unexpected version; inspect git status / previous prepare runs\");\n    }\n    r => r?,\n}","preventionTips":["Start prepare from a clean working tree (git status).","Never hand-edit Cargo.toml's version between release steps.","If a prepare run fails midway, reset Cargo.toml/Cargo.lock before retrying.","Run prepare only once per release."],"tags":["cargo","versioning","release","state-mismatch"],"backgroundTag":"invalid-state-transition","analyzedSha":"0d4ab78a4f0d9c9e5d03a50108a2ae4d2f4b2460","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}