{"record":{"id":"9d4eb61c03ad7e61","repo":"facebook/flow","slug":"failed-to-flush-errors","errorCode":null,"errorMessage":"failed to flush errors","messagePattern":"failed to flush errors","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_cli/src/foreground_check_commands.rs","lineNumber":89,"sourceCode":"                version.clone().unwrap_or(json_output::JsonVersion::JsonV1),\n                &None,\n                offset_kind,\n                errors,\n                warnings,\n            );\n            let finish_formatting = move |profiling_props| {\n                let res = get_json(profiling_props);\n                let stdout = std::io::stdout();\n                let mut out = std::io::BufWriter::new(stdout.lock());\n                use std::io::Write;\n                if pretty {\n                    write!(out, \"{}\", flow_hh_json::json_to_multiline(&res))\n                        .expect(\"failed to write errors\");\n                } else {\n                    write!(out, \"{}\", flow_hh_json::json_string_of_value(&res))\n                        .expect(\"failed to write errors\");\n                }\n                out.flush().expect(\"failed to flush errors\");\n            };\n            Box::new(move |profiling| {\n                let profiling_props = match profiling {\n                    Some(serde_json::Value::Object(profiling_props)) => {\n                        profiling_props.into_iter().collect()\n                    }\n                    Some(_) | None => vec![],\n                };\n                finish_formatting(profiling_props);\n            })\n        }\n        Printer::Cli(flags) => {\n            let errors = suppressed_errors\n                .iter()\n                .fold(errors.clone(), |mut acc, (error, _)| {\n                    acc.add(error.clone());\n                    acc\n                });","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/facebook/flow/blob/5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9/rust_port/crates/flow_cli/src/foreground_check_commands.rs#L71-L107","documentation":"The JSON output of a foreground check is buffered in a std::io::BufWriter; this expect guards the final flush. Small reports fit in the buffer, so write! succeeds into memory and the real I/O error (BrokenPipe from a closed consumer, ENOSPC from a full disk, EIO) surfaces only at this flush — making it the most common crash point of the three JSON-output expects.","triggerScenarios":"Any `flow check-contents --json ... | head ...` style pipeline where output fits the BufWriter buffer: the writes 'succeed', then flush fails when the closed pipe or full disk is finally hit.","commonSituations":"Piping status/check JSON into pagers or filters that quit early; redirecting to a filesystem at capacity; running with stdout closed.","solutions":["Avoid short-lived pipe consumers; write to a file instead.","Ensure the redirect target has space and the consumer reads to EOF.","Maintainer fix: match on flush error kind — BrokenPipe means the consumer is gone, exit 0 quietly; report anything else."],"exampleFix":"// before\nout.flush().expect(\"failed to flush errors\");\n\n// after\nif let Err(e) = out.flush() {\n    if e.kind() != std::io::ErrorKind::BrokenPipe {\n        panic!(\"failed to flush errors: {}\", e);\n    }\n    std::process::exit(0);\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(0);\n    }\n    panic!(\"failed to flush errors: {}\", e);\n}","preventionTips":["Remember BufWriter defers errors to flush — do not assume a successful write means output was delivered.","Avoid early-exiting pipe consumers in front of flow.","Check disk space before redirecting output."],"tags":["stdout","broken-pipe","flush","bufwriter","json","panic"],"backgroundTag":"broken-pipe","analyzedSha":"5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}