{"record":{"id":"a967f85f81b061c6","repo":"facebook/flow","slug":"failed-to-flush-cli-errors","errorCode":null,"errorMessage":"failed to flush cli errors","messagePattern":"failed to flush cli errors","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_cli/src/check_contents_command.rs","lineNumber":169,"sourceCode":"            warnings,\n            suppressed_errors,\n        } => {\n            if json {\n                print_json(&errors, &warnings, &suppressed_errors)\n            } else {\n                let stdout = std::io::stdout();\n                let mut out = stdout.lock();\n                flow_common_errors::error_utils::cli_output::print_errors(\n                    &mut out,\n                    &error_flags,\n                    &stdin_file,\n                    strip_root.as_deref(),\n                    &errors,\n                    &warnings,\n                    None,\n                )\n                .expect(\"failed to write cli errors\");\n                out.flush().expect(\"failed to flush cli errors\");\n                // Return a successful exit code if there were only warnings.\n                flow_common_exit_status::exit(command_utils::get_check_or_status_exit_code(\n                    &errors,\n                    &warnings,\n                    error_flags.max_warnings,\n                ))\n            }\n        }\n        server_prot::response::StatusResponse::NO_ERRORS => {\n            if json {\n                print_json(\n                    &ConcreteLocPrintableErrorSet::empty(),\n                    &ConcreteLocPrintableErrorSet::empty(),\n                    &[],\n                )\n            } else {\n                let stdout = std::io::stdout();\n                let mut out = stdout.lock();","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_cli/src/check_contents_command.rs#L151-L187","documentation":"Flush of the human-readable error report in check-contents (no --json). Identical mechanics to the JSON flush variant: the print_errors writes land in the stdout buffer while the reader is still alive, the reader then exits (head done, grep -q matched), and the explicit out.flush() returns EPIPE or ENOSPC, which the .expect() turns into a panic after the report was already emitted.","triggerScenarios":"`flow check-contents file.js | grep -m1 \"Error\"` — grep exits after the first matching error line, the flush then gets EPIPE; redirect to a filesystem that becomes full between the writes and the flush.","commonSituations":"Scripts probing CLI output with grep -q/-m1/head; pipelines whose downstream stage fails fast and closes its stdin; disk-full CI runners.","solutions":["Capture to a file first: `flow check-contents file.js > out.txt` then run grep/head on the file","Add `| cat` as the final buffering stage, or drop the early-exiting consumer","Check/free disk space when redirecting to files","Maintainer: exit quietly (141) on BrokenPipe at the flush instead of panicking"],"exampleFix":"// before\nout.flush().expect(\"failed to flush cli errors\");\n\n// after\nif let Err(e) = out.flush() {\n    if e.kind() == std::io::ErrorKind::BrokenPipe {\n        std::process::exit(141);\n    }\n    panic!(\"failed to flush cli errors: {e}\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = out.flush() {\n    if e.kind() == std::io::ErrorKind::BrokenPipe {\n        std::process::exit(141);\n    }\n    panic!(\"failed to flush cli errors: {e}\");\n}","preventionTips":["Avoid grep -q/-m1 probes directly on the command's output stream","Capture output to a file, then run grep/head against the file","Monitor disk usage when redirecting reports to files"],"tags":["rust","flow-cli","stdout","broken-pipe","flush","panic"],"backgroundTag":"broken-pipe","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T11:17:13.642Z"}