{"record":{"id":"b9a414c1b4e257db","repo":"cross-rs/cross","slug":"unable-to-get-metadata-for-package","errorCode":null,"errorMessage":"unable to get metadata for package","messagePattern":"unable to get metadata for package","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cargo.rs","lineNumber":158,"sourceCode":"    if let Some(cd) = cd {\n        command.current_dir(cd);\n    }\n    if let Some(config) = args {\n        if let Some(ref manifest_path) = config.manifest_path {\n            command.args([\"--manifest-path\".as_ref(), manifest_path.as_os_str()]);\n        }\n    } else {\n        command.arg(\"--no-deps\");\n    }\n    if let Some(target) = args.and_then(|a| a.target.as_ref()) {\n        command.args([\"--filter-platform\", target.triple()]);\n    }\n    if let Some(features) = args.map(|a| &a.features).filter(|v| !v.is_empty()) {\n        command.args([String::from(\"--features\"), features.join(\",\")]);\n    }\n    let output = command.run_and_get_output(msg_info)?;\n    if !output.status.success() {\n        msg_info.warn(\"unable to get metadata for package\")?;\n        let indented = shell::indent(&String::from_utf8(output.stderr)?, shell::default_ident());\n        msg_info.debug(indented)?;\n        return Ok(None);\n    }\n    let manifest: Option<CargoMetadata> = serde_json::from_slice(&output.stdout)?;\n    manifest\n        .map(|m| -> Result<_> {\n            Ok(CargoMetadata {\n                target_directory: args\n                    .and_then(|a| a.target_dir.clone())\n                    .unwrap_or(m.target_directory),\n                ..m\n            })\n        })\n        .transpose()\n}\n\n/// Pass-through mode","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/src/cargo.rs#L140-L176","documentation":"`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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":"// before\ncross build --target aarch64-unknown-linux-gnu --features featuures-typo\n// after\ncross build --target aarch64-unknown-linux-gnu --features features-correct  # run `cargo metadata` first to verify","handlingStrategy":"try-catch","validationCode":"// verify metadata resolves before invoking cross\ncargo metadata --format-version 1 >/dev/null || echo \"cargo metadata failed — fix Cargo.toml first\"\n# check features exist\ngrep -q \"^featu\\?res\" Cargo.toml && grep -q \"$FEATURE\" Cargo.toml","typeGuard":null,"tryCatchPattern":"// callers of cargo_metadata_with_args must handle Ok(None)\nmatch cargo_metadata_with_args(...)? {\n    Some(metadata) => proceed(metadata),\n    None => eprintln!(\"metadata unavailable: re-run with -vv to see cargo stderr\"),\n}","preventionTips":["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"],"tags":["cargo","metadata","build"],"backgroundTag":"command-not-found","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}