rust-lang/cargo · error · anyhow::Error

metadata version {} not supported, only {} is currently supp

Error message

metadata version {} not supported, only {} is currently supported

What it means

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.

Source

Thrown at src/ops/cargo_metadata.rs:29

use serde::Serialize;
use std::collections::BTreeMap;
use std::path::PathBuf;

const VERSION: u32 = 1;

pub struct OutputMetadataOptions {
    pub cli_features: CliFeatures,
    pub no_deps: bool,
    pub version: u32,
    pub filter_platforms: Vec<String>,
}

/// Loads the manifest, resolves the dependencies of the package to the concrete
/// used versions - considering overrides - and writes all dependencies in a JSON
/// format to stdout.
pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> CargoResult<ExportInfo> {
    if opt.version != VERSION {
        anyhow::bail!(
            "metadata version {} not supported, only {} is currently supported",
            opt.version,
            VERSION
        );
    }
    let (packages, resolve) = if opt.no_deps {
        let packages = ws
            .members()
            .map(|pkg| pkg.serialized(ws.gctx().cli_unstable(), ws.unstable_features()))
            .collect();
        (packages, None)
    } else {
        let (packages, resolve) = build_resolve_graph(ws, opt)?;
        (packages, Some(resolve))
    };

    Ok(ExportInfo {
        packages,

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Pass `--format-version=1` (the only currently supported version).
  2. If using cargo as a library, set OutputMetadataOptions { version: 1, ... }.
  3. Update the consuming tool to request version 1, or pin to a cargo version matching its expectation.

Example fix

# before
cargo metadata --format-version 2

# after
cargo metadata --format-version 1
Defensive patterns

Strategy: validation

Validate before calling

// Only the single supported metadata version is accepted.
const SUPPORTED_METADATA_VERSION: u32 = 1;

fn build_opts(version: u32) -> Result<OutputMetadataOptions, String> {
    if version != SUPPORTED_METADATA_VERSION {
        return Err(format!("metadata version {} not supported; use 1", version));
    }
    Ok(OutputMetadataOptions { version, ..Default::default() })
}

Type guard

fn is_supported_version(v: u32) -> bool {
    v == 1
}

Try / catch

match ops::output_metadata(ws, &opts) {
    Err(e) if e.to_string().contains("metadata version") => {
        eprintln!("only metadata format-version 1 is supported");
        return Err(e);
    }
    r => r,
}

Prevention

When it happens

Trigger: Calling `cargo metadata --format-version 2` (or 0, or omitting the version in a caller that defaults differently). The opt.version != VERSION check bails.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/9f34c55a43dee4b0.json. Report an issue: GitHub.