BoundaryML/baml · error
cargo metadata failed
Error message
cargo metadata failed
What it means
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.
Source
Thrown at baml_language/crates/tools_size_gate/src/main.rs:197
};
match result {
Ok(code) => std::process::exit(code),
Err(e) => {
eprintln!("error: {e:#}");
std::process::exit(EXIT_TOOL_ERROR);
}
}
}
/// Find the workspace root via cargo metadata.
fn find_workspace_root() -> Result<PathBuf> {
let output = std::process::Command::new("cargo")
.args(["metadata", "--no-deps", "--format-version", "1"])
.output()
.context("failed to run cargo metadata")?;
if !output.status.success() {
anyhow::bail!("cargo metadata failed");
}
let json: serde_json::Value = serde_json::from_slice(&output.stdout)?;
let root = json["workspace_root"]
.as_str()
.context("no workspace_root in metadata")?;
Ok(PathBuf::from(root))
}
/// Determine which artifact names are relevant for the current host.
/// Returns a map: platform -> artifact names.
fn relevant_artifacts(config: &Config, filter: Option<&[String]>) -> BTreeMap<String, Vec<String>> {
let host = host_triple();
let mut groups: BTreeMap<String, Vec<String>> = BTreeMap::new();
for (name, artifact) in &config.artifacts {
if let Some(only) = filter {
if !only.iter().any(|o| o == name) {
continue;View on GitHub (pinned to bd85ce9dee)
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)
Example fix
// before: wrong cwd $ cd /tmp && size-gate check cargo metadata failed // after $ cd baml_language && size-gate check
Defensive patterns
Strategy: validation
Validate before calling
let ok = std::process::Command::new("cargo")
.args(["metadata", "--no-deps", "--format-version", "1"])
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if !ok { eprintln!("not in a valid cargo workspace; run from the repo root"); std::process::exit(1); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- cargo build failed for {package}
- cargo build failed for pack ({} + {})
- cargo metadata failed
- package '{package_name}' not found in cargo metadata
- Failed to load cargo metadata: {e}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/7c889c22fca9a556.
Report an issue: GitHub.