{"record":{"id":"034ba5c597aaa8bf","repo":"rust-lang/cargo","slug":"build-script-logged-errors","errorCode":null,"errorMessage":"build script logged errors","messagePattern":"build script logged errors","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/custom_build.rs","lineNumber":672,"sourceCode":"                build_script_outputs,\n                id,\n                metadata_hash,\n                log_messages_in_case_of_panic,\n            );\n            return Err(error);\n        }\n        // ... or it logged any errors\n        else if log_messages_in_case_of_panic\n            .iter()\n            .any(|(severity, _)| *severity == Severity::Error)\n        {\n            insert_log_messages_in_build_outputs(\n                build_script_outputs,\n                id,\n                metadata_hash,\n                log_messages_in_case_of_panic,\n            );\n            anyhow::bail!(\"build script logged errors\");\n        }\n\n        let output = output.unwrap();\n\n        // After the build command has finished running, we need to be sure to\n        // remember all of its output so we can later discover precisely what it\n        // was, even if we don't run the build command again (due to freshness).\n        //\n        // This is also the location where we provide feedback into the build\n        // state informing what variables were discovered via our script as\n        // well.\n        paths::write(&run_files.stdout, &output.stdout)?;\n        // This mtime shift allows Cargo to detect if a source file was\n        // modified in the middle of the build.\n        paths::set_file_time_no_err(run_files.stdout, timestamp);\n        paths::write(&run_files.stderr, &output.stderr)?;\n        paths::write(&run_files.root_output, paths::path2bytes(&script_out_dir)?)?;\n        let parsed_output = BuildOutput::parse(","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/compiler/custom_build.rs#L654-L690","documentation":"A build script (`build.rs`) finished, but Cargo's collected log messages contain at least one with `Severity::Error`. Cargo treats this as a build failure even if the process exited 0, surfacing the captured messages via `insert_log_messages_in_build_outputs` and bailing with the generic `\"build script logged errors\"`.","triggerScenarios":"A build script writes to stderr in a format Cargo interprets as an error (or uses `cargo:warning`/error-level directives that escalate), or a panic-style message was logged before completion; often from `println!(\"cargo:...\")` misuse or an explicit error emission.","commonSituations":"Build scripts that print to stderr expecting it to be ignored; crates whose `build.rs` emits `cargo:rustc-link-lib` after a partial failure; panics in build scripts whose messages are captured.","solutions":["Re-run with `cargo build -vv` to see the build script's logged messages surfaced in build outputs.","Fix the build script to not emit error-level output; route diagnostics to a file or use `cargo:warning` intentionally.","Ensure the build script exits non-zero only on real failure and zero on success with no error logs.","If using a build-dependency that misbehaves, pin or patch it."],"exampleFix":"// before (build.rs)\neprintln!(\"error: something went wrong but we continue\");\nOk(())\n\n// after\neprintln!(\"warning: non-fatal, continuing\");\nOk(())","handlingStrategy":"try-catch","validationCode":"fn build_script_emits_no_errors(logs: &[(Severity, String)]) -> bool {\n    !logs.iter().any(|(s, _)| *s == Severity::Error)\n}","typeGuard":"null","tryCatchPattern":"match run_build_script(unit) {\n    Err(e) if e.to_string() == \"build script logged errors\" => {\n        log::error!(\"build script reported errors; see build output\"); surface_build_outputs()\n    }\n    r => r,\n}","preventionTips":["In `build.rs`, route non-fatal diagnostics to a file or `cargo:warning`.","Exit non-zero only on hard failure; never leave error logs on success path.","Test build scripts with `-vv` locally before publishing."],"tags":["cargo","build-script","build-output","diagnostics"],"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"}