{"record":{"id":"c8dd55a43f480404","repo":"dbt-labs/dbt-core","slug":"failed-to-write-show-result-to-stdout","errorCode":null,"errorMessage":"failed to write show result to stdout","messagePattern":"failed to write show result to stdout","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-common/src/tracing/layers/tui_layer.rs","lineNumber":1442,"sourceCode":"            let mut stdout = io::stdout().lock();\n\n            stdout\n                .write_all(format!(\"{}\\n\", show_data.content).as_bytes())\n                .expect(\"failed to write show data to stdout\");\n        });\n    }\n\n    fn handle_show_result(&self, show_result: &ShowResult) {\n        self.write_suspended(|| {\n            let mut stdout = io::stdout().lock();\n\n            if self.show_options.is_empty() {\n                // Quiet mode: suppress decorative title, emit raw content only.\n                // Mirrors dbt-core's ShowNode quiet=True behaviour where the\n                // \"Previewing node 'X':\" header is dropped but the data is kept.\n                stdout\n                    .write_all(format!(\"{}\\n\", show_result.content).as_bytes())\n                    .expect(\"failed to write show result to stdout\");\n            } else {\n                let colored_title = BLUE.apply_to(&show_result.title);\n                stdout\n                    .write_all(format!(\"\\n{}\\n{}\\n\", colored_title, show_result.content).as_bytes())\n                    .expect(\"failed to write show result to stdout\");\n            }\n        });\n    }\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;","sourceCodeStart":1424,"sourceCodeEnd":1460,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-common/src/tracing/layers/tui_layer.rs#L1424-L1460","documentation":"This panic comes from an `.expect()` on `Stdout::write_all` inside the TUI tracing layer's `handle_show_result`. It fires when dbt fails to write a `show` result (in quiet mode: raw content, no title header) to stdout. The most common underlying cause is a broken pipe — the downstream consumer (e.g. `head`, a pager, or a closed terminal) has stopped reading or the pipe is closed, so the write fails and the panic message surfaces instead of the data.","triggerScenarios":"A dbt `show` invocation whose output is piped into a command that exits early (e.g. `dbt show ... | head -5`), or whose stdout is a closed/invalid file descriptor, causing `write_all` on the locked stdout to return Err and the `.expect` to panic.","commonSituations":"Developers piping `dbt show` output into `head`, `less -F`, or a script that exits before reading all output; running dbt in CI with stdout redirected to a closed stream; terminal emulators closing the PTY mid-run.","solutions":["Avoid piping dbt output to commands that exit early (e.g. `head`); redirect to a file instead: `dbt show ... > out.txt`.","Set RUST_BACKTRACE=1 and check the panic source; if it is broken-pipe, confirm the downstream reader consumes all output.","Restore a valid stdout — run dbt in a live terminal or with stdout attached to a file, not a closed descriptor.","If the process must survive closed pipes, invoke dbt with output to stderr only (quiet/suppress options) so the show-result write path is not hit.","Upgrade dbt — newer versions may replace `.expect` with graceful SIGPIPE handling."],"exampleFix":"// before\nstdout\n    .write_all(format!(\"{}\\n\", show_result.content).as_bytes())\n    .expect(\"failed to write show result to stdout\");\n// after\nlet _ = stdout\n    .write_all(format!(\"{}\\n\", show_result.content).as_bytes());\nstdout.flush().ok();","handlingStrategy":"try-catch","validationCode":"// bash: ensure stdout is writable and no early-exiting pipe consumer\n[ -w /dev/stdout ] && echo \"stdout writable\"","typeGuard":null,"tryCatchPattern":"// from the library side: replace expect with error-tolerant write\nif let Err(e) = stdout.write_all(bytes) {\n    eprintln!(\"show result not written: {e}\");\n}","preventionTips":["Never pipe dbt output into commands that exit early (head, grep -q)","Redirect to files when automating: dbt show > out.txt","Keep pipe readers open until the dbt process exits","Run dbt in a live terminal for interactive output"],"tags":["rust","stdout","broken-pipe","panics","tui"],"backgroundTag":"broken-pipe","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}