{"record":{"id":"ba89263958971979","repo":"dbt-labs/dbt-core","slug":"failed-to-write-compiled-code-to-stdout","errorCode":null,"errorMessage":"failed to write compiled code to stdout","messagePattern":"failed to write compiled code to stdout","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-common/src/tracing/layers/tui_layer.rs","lineNumber":1468,"sourceCode":"    }\n\n    fn handle_compiled_code_inline(&self, compiled_code: &CompiledCodeInline) {\n        // Only show if any Progress*, Completed or All option is enabled\n        let should_show = self.show_options.contains(&ShowOptions::Progress)\n            || self.show_options.contains(&ShowOptions::ProgressRender)\n            || self.show_options.contains(&ShowOptions::Completed)\n            || self.show_options.contains(&ShowOptions::All);\n\n        if !should_show {\n            return;\n        }\n\n        let formatted = format_compiled_inline_code(compiled_code, true);\n        self.write_suspended(|| {\n            io::stdout()\n                .lock()\n                .write_all(format!(\"{}\\n\", formatted).as_bytes())\n                .expect(\"failed to write compiled code to stdout\");\n        });\n    }\n\n    fn handle_compiled_code(&self, compiled_code: &CompiledCode) {\n        if self.command != FsCommand::Compile {\n            return;\n        }\n\n        if !should_show_progress_message(ExecutionPhase::Render, &self.show_options) {\n            return;\n        }\n\n        let formatted = format_compiled_code(compiled_code, true);\n        self.write_suspended(|| {\n            io::stdout()\n                .lock()\n                .write_all(format!(\"{}\\n\", formatted).as_bytes())\n                .expect(\"failed to write compiled code to stdout\");","sourceCodeStart":1450,"sourceCodeEnd":1486,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-common/src/tracing/layers/tui_layer.rs#L1450-L1486","documentation":"`handle_compiled_code_inline` formats compiled inline SQL (via `format_compiled_inline_code`) and writes it to a locked stdout with `.expect(\"failed to write compiled code to stdout\")`. The panic means the byte write failed, almost always a broken pipe because the process reading stdout exited or was closed before consuming the compiled code output.","triggerScenarios":"Running dbt (e.g. `dbt compile`/`dbt run` with inline compiled-code display enabled) while stdout is piped to an early-exiting consumer, or stdout is an invalid/closed descriptor, during `on_log_record` handling of a CompiledCodeInline event.","commonSituations":"`dbt compile | head -20`; log forwards that close the pipe; CI systems killing the reader while dbt still streams output.","solutions":["Pipe to a consumer that reads everything, or redirect to a file: `dbt compile > compiled.sql`.","Check `echo $?` and RUST_BACKTRACE to confirm broken-pipe (typically exit code 101 with this panic).","Ensure the terminal/PTY stays open for the whole run.","Upgrade dbt for non-panicking stdout write handling."],"exampleFix":"// before\nio::stdout()\n    .lock()\n    .write_all(format!(\"{}\\n\", formatted).as_bytes())\n    .expect(\"failed to write compiled code to stdout\");\n// after\nlet _ = io::stdout()\n    .lock()\n    .write_all(format!(\"{}\\n\", formatted).as_bytes());","handlingStrategy":"try-catch","validationCode":"// bash: capture instead of truncating pipe\ndbt compile > compiled.out 2> compile.err; echo $?","typeGuard":null,"tryCatchPattern":"if let Err(e) = io::stdout().lock().write_all(bytes) {\n    eprintln!(\"compiled code not written: {e}\");\n}","preventionTips":["Don't truncate `dbt compile` output with head/early-exit filters","Redirect to files in CI","Drain child stdout in wrapper scripts","Keep terminals/SSH sessions alive during compile"],"tags":["rust","stdout","broken-pipe","panics","tracing"],"backgroundTag":"broken-pipe","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}