{"record":{"id":"4490b10964d12fe2","repo":"BoundaryML/baml","slug":"cargo-metadata-failed-measure","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/measure.rs","lineNumber":243,"sourceCode":"/// Append the platform executable extension (`.exe` on Windows).\nfn exe_filename(stem: &str) -> String {\n    if cfg!(target_os = \"windows\") {\n        format!(\"{stem}.exe\")\n    } else {\n        stem.to_owned()\n    }\n}\n\n/// Resolve the lib name for a package using cargo metadata.\nfn resolve_lib_name(workspace_root: &Path, package_name: &str) -> Result<String> {\n    let output = Command::new(\"cargo\")\n        .args([\"metadata\", \"--no-deps\", \"--format-version\", \"1\"])\n        .current_dir(workspace_root)\n        .output()\n        .context(\"failed to run cargo metadata\")?;\n\n    if !output.status.success() {\n        bail!(\"cargo metadata failed\");\n    }\n\n    let json: serde_json::Value =\n        serde_json::from_slice(&output.stdout).context(\"failed to parse cargo metadata\")?;\n\n    let packages = json[\"packages\"]\n        .as_array()\n        .context(\"no packages in metadata\")?;\n\n    for pkg in packages {\n        if pkg[\"name\"].as_str() == Some(package_name) {\n            if let Some(targets) = pkg[\"targets\"].as_array() {\n                for target in targets {\n                    let kinds = target[\"kind\"].as_array();\n                    let is_cdylib = kinds\n                        .map(|k| k.iter().any(|v| v.as_str() == Some(\"cdylib\")))\n                        .unwrap_or(false);\n                    if is_cdylib {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/tools_size_gate/src/measure.rs#L225-L261","documentation":"resolve_lib_name shells out to `cargo metadata --no-deps --format-version 1` from the workspace root. If cargo exits with a non-zero status, the tool bails with this short message. It indicates cargo itself rejected the invocation or the workspace, not that JSON parsing failed.","triggerScenarios":"locate_artifact needs to map a package name to its library name and invokes cargo metadata in a workspace where the command fails: invalid Cargo.toml, unparsable lockfile, cargo not resolvable in PATH context, or bad current_dir.","commonSituations":"Corrupted or hand-edited Cargo.toml/lockfile; running from an environment where cargo is missing or a toolchain shim fails; workspace_root pointing at a non-cargo directory; dependency resolution requiring network while offline.","solutions":["Run `cargo metadata --no-deps` manually in the workspace root to see the real cargo error.","Fix the underlying Cargo.toml/lockfile error cargo reports.","Ensure workspace_root points to the actual workspace containing Cargo.toml.","Verify the cargo toolchain (rustup update / correct PATH) used by the gate matches your shell."],"exampleFix":"// diagnose before running gate\\ncd <workspace_root> && cargo metadata --no-deps --format-version 1\\n// fix whatever cargo reports, then re-run the size gate","handlingStrategy":"try-catch","validationCode":"let probe = Command::new(\"cargo\").args([\"metadata\",\"--no-deps\",\"--format-version\",\"1\"]).current_dir(workspace_root).output()?;\\nif !probe.status.success() { eprintln!(\"cargo metadata failed: {}\", String::from_utf8_lossy(&probe.stderr)); }","typeGuard":null,"tryCatchPattern":"match load_result {\\n    Err(e) if e.to_string().contains(\"cargo metadata failed\") => {\\n        eprintln!(\"Run `cargo metadata --no-deps` in the workspace root to see the real error.\");\\n        std::process::exit(1);\\n    }\\n    other => other?,\\n}","preventionTips":["Validate Cargo.toml/lockfile health before running tooling.","Ensure a working cargo is on PATH in all CI environments.","Pin/lock the rust toolchain via rust-toolchain.toml.","Never hand-edit Cargo.lock while tooling runs concurrently."],"tags":["rust","cargo","build"],"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"}