{"record":{"id":"e8a39cc16d0575de","repo":"facebook/flow","slug":"failed-to-flush-success-output","errorCode":null,"errorMessage":"failed to flush success output","messagePattern":"failed to flush success output","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_cli/src/check_contents_command.rs","lineNumber":189,"sourceCode":"                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();\n                writeln!(out, \"No errors!\").expect(\"failed to write success output\");\n                out.flush().expect(\"failed to flush success output\");\n            }\n            flow_common_exit_status::exit(flow_common_exit_status::FlowExitStatus::NoError)\n        }\n        server_prot::response::StatusResponse::NOT_COVERED => {\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();\n                writeln!(out, \"File is not @flow!\").expect(\"failed to write not-covered output\");\n                out.flush().expect(\"failed to flush not-covered output\");\n            }\n            flow_common_exit_status::exit(flow_common_exit_status::FlowExitStatus::NoError)\n        }","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_cli/src/check_contents_command.rs#L171-L207","documentation":"Flush right after the 'No errors!' line in check-contents. Because a single short line fits in the kernel pipe buffer, the writeln usually succeeds even if the reader is finishing; the reader then fully exits (e.g. grep -q matched the line), the pipe's read end closes, and this explicit out.flush() gets EPIPE — the canonical race that the .expect() turns into a panic.","triggerScenarios":"`flow check-contents file.js | grep -q 'No errors'` — grep matches the line, exits, and the subsequent flush hits EPIPE; a probe command exiting between the write and the flush; flush to a full filesystem.","commonSituations":"CI pipelines that assert on success output via grep -q; short-output commands piped into probes; redirects to full volumes.","solutions":["Use the exit code instead of probing output: `flow check-contents file.js && echo ok`","Capture to a file and grep the file rather than the stream","Wrap the pipeline in a buffer (`| cat`) so the flush always finds a live reader","Maintainer: exit quietly (141) on BrokenPipe at the flush instead of expect"],"exampleFix":"// before\nout.flush().expect(\"failed to flush success output\");\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 success output: {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 success output: {e}\");\n}","preventionTips":["Prefer `flow check-contents file.js && echo ok` over `| grep -q 'No errors'`","When probing output is unavoidable, capture to a file first","Remember a one-line write can succeed while its flush still fails — test the flush path"],"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"}