{"id":"9f34c55a43dee4b0","repo":"rust-lang/cargo","slug":"metadata-version-not-supported-only-is-curr","errorCode":null,"errorMessage":"metadata version {} not supported, only {} is currently supported","messagePattern":"metadata version (.+?) not supported, only (.+?) is currently supported","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_metadata.rs","lineNumber":29,"sourceCode":"use serde::Serialize;\nuse std::collections::BTreeMap;\nuse std::path::PathBuf;\n\nconst VERSION: u32 = 1;\n\npub struct OutputMetadataOptions {\n    pub cli_features: CliFeatures,\n    pub no_deps: bool,\n    pub version: u32,\n    pub filter_platforms: Vec<String>,\n}\n\n/// Loads the manifest, resolves the dependencies of the package to the concrete\n/// used versions - considering overrides - and writes all dependencies in a JSON\n/// format to stdout.\npub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> CargoResult<ExportInfo> {\n    if opt.version != VERSION {\n        anyhow::bail!(\n            \"metadata version {} not supported, only {} is currently supported\",\n            opt.version,\n            VERSION\n        );\n    }\n    let (packages, resolve) = if opt.no_deps {\n        let packages = ws\n            .members()\n            .map(|pkg| pkg.serialized(ws.gctx().cli_unstable(), ws.unstable_features()))\n            .collect();\n        (packages, None)\n    } else {\n        let (packages, resolve) = build_resolve_graph(ws, opt)?;\n        (packages, Some(resolve))\n    };\n\n    Ok(ExportInfo {\n        packages,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_metadata.rs#L11-L47","documentation":"Thrown in output_metadata (src/ops/cargo_metadata.rs:28-34) when the requested metadata format version differs from the only supported version (VERSION = 1). `cargo metadata --format-version=N` with N != 1 is rejected outright before any resolution runs.","triggerScenarios":"Calling `cargo metadata --format-version 2` (or 0, or omitting the version in a caller that defaults differently). The opt.version != VERSION check bails.","commonSituations":"A tool assuming a newer metadata format. A typo'd version number. Scripts pinning to a future version that does not exist yet. Cargo version mismatch between the tool and the installed cargo.","solutions":["Pass `--format-version=1` (the only currently supported version).","If using cargo as a library, set OutputMetadataOptions { version: 1, ... }.","Update the consuming tool to request version 1, or pin to a cargo version matching its expectation."],"exampleFix":"# before\ncargo metadata --format-version 2\n\n# after\ncargo metadata --format-version 1","handlingStrategy":"validation","validationCode":"// Only the single supported metadata version is accepted.\nconst SUPPORTED_METADATA_VERSION: u32 = 1;\n\nfn build_opts(version: u32) -> Result<OutputMetadataOptions, String> {\n    if version != SUPPORTED_METADATA_VERSION {\n        return Err(format!(\"metadata version {} not supported; use 1\", version));\n    }\n    Ok(OutputMetadataOptions { version, ..Default::default() })\n}","typeGuard":"fn is_supported_version(v: u32) -> bool {\n    v == 1\n}","tryCatchPattern":"match ops::output_metadata(ws, &opts) {\n    Err(e) if e.to_string().contains(\"metadata version\") => {\n        eprintln!(\"only metadata format-version 1 is supported\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Hard-code `--format-version=1` in scripts and tools.","When using cargo as a library, set OutputMetadataOptions.version = 1."],"tags":["cargo","metadata","versioning","cli","api"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}