{"record":{"id":"670d6776a7ce99a9","repo":"facebook/flow","slug":"failed-to-write-errors","errorCode":null,"errorMessage":"failed to write errors","messagePattern":"failed to write errors","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_cli/src/foreground_check_commands.rs","lineNumber":84,"sourceCode":"            let strip_root = strip_root.map(|path| path.to_string_lossy().into_owned());\n            let pretty = *pretty;\n            let get_json = json_output::full_status_json_of_errors(\n                strip_root.as_deref(),\n                suppressed_errors,\n                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","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/facebook/flow/blob/5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9/rust_port/crates/flow_cli/src/foreground_check_commands.rs#L66-L102","documentation":"After a foreground (check-and-die) run with JSON output (e.g. `flow check-contents --json --pretty`), the CLI formats the error report and writes it to a BufWriter over stdout. This expect is on the pretty-printed branch (flow_hh_json::json_to_multiline) and panics on any write error. Because Rust ignores SIGPIPE, a downstream consumer that exited early surfaces here as ErrorKind::BrokenPipe instead of a signal.","triggerScenarios":"`flow check-contents --json --pretty | head -n 5` (head exits after 5 lines, closing the pipe); a downstream filter that exits early (grep -m1, jq ... | head); stdout redirected to a full filesystem (ENOSPC); stdout closed with `>&-`.","commonSituations":"Piping large JSON check output into head/grep in scripts; CI capturing output to a full disk or size-capped artifact; a consumer tool crashing mid-stream.","solutions":["Write to a file first and inspect it separately: `flow check-contents --json --pretty > report.json`.","Keep the pipe consumer alive until EOF (drop `head`/`grep -m` from the pipeline).","If redirecting to a file, free disk space / raise quota.","Maintainer fix: treat ErrorKind::BrokenPipe as a clean exit(0), the standard CLI convention."],"exampleFix":"// before\nwrite!(out, \"{}\", flow_hh_json::json_to_multiline(&res))\n    .expect(\"failed to write errors\");\n\n// after\nif let Err(e) = write!(out, \"{}\", flow_hh_json::json_to_multiline(&res)) {\n    if e.kind() == std::io::ErrorKind::BrokenPipe {\n        std::process::exit(0);\n    }\n    panic!(\"failed to write errors: {}\", e);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = write!(out, \"{}\", flow_hh_json::json_to_multiline(&res)) {\n    if e.kind() == std::io::ErrorKind::BrokenPipe {\n        std::process::exit(0);\n    }\n    panic!(\"failed to write errors: {}\", e);\n}","preventionTips":["Redirect large JSON reports to files instead of piping to head/grep -m.","Keep downstream consumers reading until EOF.","Ensure redirected targets have free disk space; never run with stdout closed."],"tags":["stdout","broken-pipe","json","io-error","panic","check-contents"],"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"}