{"record":{"id":"ca977566f105ed6e","repo":"rust-lang/cargo","slug":"malformed-output-when-learning-about-crate-type","errorCode":null,"errorMessage":"malformed output when learning about crate-type {} information\n{}","messagePattern":"malformed output when learning about crate-type (.+?) information\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/build_context/target_info.rs","lineNumber":710,"sourceCode":"///\n/// This function can not handle more than one file per type (with wasm32-unknown-emscripten, there\n/// are two files for bin (`.wasm` and `.js`)).\nfn parse_crate_type(\n    crate_type: &CrateType,\n    cmd: &ProcessBuilder,\n    output: &str,\n    error: &str,\n    lines: &mut str::Lines<'_>,\n) -> CargoResult<Option<(String, String)>> {\n    let not_supported = error.lines().any(|line| {\n        (line.contains(\"unsupported crate type\") || line.contains(\"unknown crate type\"))\n            && line.contains(&format!(\"crate type `{}`\", crate_type))\n    });\n    if not_supported {\n        return Ok(None);\n    }\n    let Some(line) = lines.next() else {\n        anyhow::bail!(\n            \"malformed output when learning about crate-type {} information\\n{}\",\n            crate_type,\n            output_err_info(cmd, output, error)\n        )\n    };\n    let mut parts = line.trim().split(\"___\");\n    let prefix = parts.next().unwrap();\n    let Some(suffix) = parts.next() else {\n        return error_missing_print_output(\"file-names\", cmd, output, error);\n    };\n\n    Ok(Some((prefix.to_string(), suffix.to_string())))\n}\n\n/// Helper for creating an error message for missing output from a certain `--print` request.\nfn error_missing_print_output<T>(\n    request: &str,\n    cmd: &ProcessBuilder,","sourceCodeStart":692,"sourceCodeEnd":728,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/compiler/build_context/target_info.rs#L692-L728","documentation":"While querying `rustc` for metadata about a crate type (e.g. `cdylib`, `bin`), Cargo expected a line of output but the iterator was empty. This happens in `parse_fingerprint`/`rustc --print` probing where rustc is invoked to learn file names for a specific crate type but produced no line to consume.","triggerScenarios":"Running a build for a crate type the active toolchain's rustc emits nothing for, or when rustc output is truncated/malformed (e.g. a broken toolchain, an injected `RUSTC_WRAPPER` that swallows stdout, or a misconfigured `--print` query).","commonSituations":"Switching toolchains (nightly vs stable) where a crate type is partially supported; sccache or other wrappers corrupting rustc stdout; cross-compilation with a target that lacks full crate-type support; partial rustc installations.","solutions":["Re-run with `cargo build -vv` to capture the exact rustc command and stdout/stderr shown in the error's `output_err_info`.","Disable any `RUSTC_WRAPPER`/`RUSTC_WORKSPACE_WRAPPER` (e.g. sccache) and retry to isolate wrapper corruption.","Verify the crate type is valid for the target: check `[lib] crate-type` in `Cargo.toml` against the target's supported types.","Reinstall/switch the toolchain with `rustup update` or `rustup override set stable`."],"exampleFix":"// before\nRUSTC_WRAPPER=sccache cargo build --target wasm32-wasi\n\n// after (isolate wrapper)\nunset RUSTC_WRAPPER\ncargo build --target wasm32-wasi -vv","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"match target_info::parse_file_names(&output, &err, &mut lines) {\n    Ok(Some((p, s))) => Ok(()),\n    Ok(None) => Ok(()), // unsupported crate type, handle gracefully\n    Err(e) => { log::warn!(\"rustc crate-type probe failed: {e}\"); disable_wrapper_and_retry()? },\n}","preventionTips":["Pin a known-good toolchain in CI (`rustup default <pinned>`).","Test `RUSTC_WRAPPER`s against a `--print` query before trusting them.","Validate the target supports the crate-type before building (`rustc --print=crate-types --target <t>`)."],"tags":["cargo","rustc","crate-type","toolchain","wrapper"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}