{"record":{"id":"7c889c22fca9a556","repo":"BoundaryML/baml","slug":"cargo-metadata-failed","errorCode":null,"errorMessage":"cargo metadata failed","messagePattern":"cargo metadata failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/tools_size_gate/src/main.rs","lineNumber":197,"sourceCode":"    };\n\n    match result {\n        Ok(code) => std::process::exit(code),\n        Err(e) => {\n            eprintln!(\"error: {e:#}\");\n            std::process::exit(EXIT_TOOL_ERROR);\n        }\n    }\n}\n\n/// Find the workspace root via cargo metadata.\nfn find_workspace_root() -> Result<PathBuf> {\n    let output = std::process::Command::new(\"cargo\")\n        .args([\"metadata\", \"--no-deps\", \"--format-version\", \"1\"])\n        .output()\n        .context(\"failed to run cargo metadata\")?;\n    if !output.status.success() {\n        anyhow::bail!(\"cargo metadata failed\");\n    }\n    let json: serde_json::Value = serde_json::from_slice(&output.stdout)?;\n    let root = json[\"workspace_root\"]\n        .as_str()\n        .context(\"no workspace_root in metadata\")?;\n    Ok(PathBuf::from(root))\n}\n\n/// Determine which artifact names are relevant for the current host.\n/// Returns a map: platform -> artifact names.\nfn relevant_artifacts(config: &Config, filter: Option<&[String]>) -> BTreeMap<String, Vec<String>> {\n    let host = host_triple();\n    let mut groups: BTreeMap<String, Vec<String>> = BTreeMap::new();\n\n    for (name, artifact) in &config.artifacts {\n        if let Some(only) = filter {\n            if !only.iter().any(|o| o == name) {\n                continue;","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/tools_size_gate/src/main.rs#L179-L215","documentation":"find_workspace_root runs `cargo metadata --no-deps --format-version 1` to locate the workspace root; if cargo exits non-zero it bails with this generic message. It means cargo itself rejected the invocation — usually because the current directory is not inside a valid Cargo workspace or the manifest is broken.","triggerScenarios":"Running size-gate (record/check/bake/diff) from a directory outside a Cargo workspace, or with a corrupt/invalid Cargo.toml, or a broken Rust toolchain.","commonSituations":"Invoking the tool from a random directory instead of the repo root; malformed workspace members in Cargo.toml; rustup toolchain missing; cargo not on PATH (that instead yields the 'failed to run cargo metadata' context error).","solutions":["Run size-gate from the repository/workspace root (or a subdirectory of it)","Run `cargo metadata --no-deps --format-version 1` manually to see cargo's real error","Fix the invalid Cargo.toml that cargo reports","Ensure a working Rust toolchain is installed (rustup update stable)"],"exampleFix":"// before: wrong cwd\n$ cd /tmp && size-gate check\ncargo metadata failed\n// after\n$ cd baml_language && size-gate check","handlingStrategy":"validation","validationCode":"let ok = std::process::Command::new(\"cargo\")\n    .args([\"metadata\", \"--no-deps\", \"--format-version\", \"1\"])\n    .output()\n    .map(|o| o.status.success())\n    .unwrap_or(false);\nif !ok { eprintln!(\"not in a valid cargo workspace; run from the repo root\"); std::process::exit(1); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run size-gate from the workspace root or a subdirectory of it","Add a CI preflight `cargo metadata --no-deps` sanity check","Validate Cargo.toml after editing workspace members","Ensure rustup/cargo are installed in the CI image"],"tags":["cargo","rust","workspace","subprocess"],"backgroundTag":"command-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}