cross-rs/cross · warning
unable to get metadata for package
Error message
unable to get metadata for package
What it means
`cargo_metadata_with_args` (src/cargo.rs:158) runs `cargo metadata` for the package. When the command exits non-zero, cross logs the warning "unable to get metadata for package", dumps the indented stderr at debug level, and returns `Ok(None)` — the caller (`cargo_metadata`, `run`) must then handle the missing metadata. It is a warning surfaced to the user, not a panic; the actual cargo error text is hidden unless debug logging is on.
Solutions
- Re-run with `-vv` / `--verbose` (or RUST_LOG=debug) to see the indented stderr from cargo metadata, which names the real cause
- Fix the underlying Cargo.toml / feature list error reported by running `cargo metadata --format-version 1` manually
- Check network/proxy settings or vendored/offline configuration if the failure is a registry fetch
- Ensure the `--features` values passed to cross exist in Cargo.toml
Example fix
// before cross build --target aarch64-unknown-linux-gnu --features featuures-typo // after cross build --target aarch64-unknown-linux-gnu --features features-correct # run `cargo metadata` first to verify
Defensive patterns
Strategy: try-catch
Validate before calling
// verify metadata resolves before invoking cross cargo metadata --format-version 1 >/dev/null || echo "cargo metadata failed — fix Cargo.toml first" # check features exist grep -q "^featu\?res" Cargo.toml && grep -q "$FEATURE" Cargo.toml
Try / catch
// callers of cargo_metadata_with_args must handle Ok(None)
match cargo_metadata_with_args(...)? {
Some(metadata) => proceed(metadata),
None => eprintln!("metadata unavailable: re-run with -vv to see cargo stderr"),
} Prevention
- Run `cargo metadata --format-version 1` manually to surface the real cargo error
- Enable debug logging (-vv) with cross so the indented stderr is visible
- Validate feature names and Cargo.toml syntax before cross runs, especially in CI
- Check network/offline config (CARGO_NET_OFFLINE, vendored sources) when metadata involves registry access
When it happens
Trigger: `cargo metadata` failing: invalid Cargo.toml, unparsable `--features` list passed via args, a dependency that fails to resolve, an offline/network failure fetching the registry index, or a broken workspace.
Common situations: Typo in a feature name passed to cross, malformed Cargo.toml after an edit, network is down / CARGO_NET_OFFLINE with an uncached index, or a workspace member with invalid manifest.
Related errors
- unable to find dockerfile for target
- unable to find native dockerfile named
- no valid choice to pick for image name
AI-assisted analysis of cross-rs/cross@8c1a8aa4b6 (2026-09-13).
Data as JSON: /api/errors/b9a414c1b4e257db.
Report an issue: GitHub.
Appendix: source
Thrown at src/cargo.rs:158
if let Some(cd) = cd {
command.current_dir(cd);
}
if let Some(config) = args {
if let Some(ref manifest_path) = config.manifest_path {
command.args(["--manifest-path".as_ref(), manifest_path.as_os_str()]);
}
} else {
command.arg("--no-deps");
}
if let Some(target) = args.and_then(|a| a.target.as_ref()) {
command.args(["--filter-platform", target.triple()]);
}
if let Some(features) = args.map(|a| &a.features).filter(|v| !v.is_empty()) {
command.args([String::from("--features"), features.join(",")]);
}
let output = command.run_and_get_output(msg_info)?;
if !output.status.success() {
msg_info.warn("unable to get metadata for package")?;
let indented = shell::indent(&String::from_utf8(output.stderr)?, shell::default_ident());
msg_info.debug(indented)?;
return Ok(None);
}
let manifest: Option<CargoMetadata> = serde_json::from_slice(&output.stdout)?;
manifest
.map(|m| -> Result<_> {
Ok(CargoMetadata {
target_directory: args
.and_then(|a| a.target_dir.clone())
.unwrap_or(m.target_directory),
..m
})
})
.transpose()
}
/// Pass-through modeView on GitHub (pinned to 8c1a8aa4b6)