{"record":{"id":"826fef0e508fd7e2","repo":"facebook/flow","slug":"failed-to-write-json-errors-826fef","errorCode":null,"errorMessage":"failed to write json errors","messagePattern":"failed to write json errors","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_cli/src/status_command.rs","lineNumber":149,"sourceCode":"         suppressed_errors: &[(PrintableError<Loc>, BTreeSet<Loc>)]| {\n            let strip_root = strip_root\n                .as_deref()\n                .map(|root| root.to_string_lossy().into_owned());\n            let stdout = std::io::stdout();\n            let mut out = stdout.lock();\n            flow_common_errors::error_utils::json_output::print_errors_with_offset_kind(\n                &mut out,\n                strip_root.as_deref(),\n                suppressed_errors,\n                args.pretty,\n                args.output_json_version\n                    .unwrap_or(json_output::JsonVersion::JsonV1),\n                &None,\n                offset_kind,\n                errors,\n                warnings,\n            )\n            .expect(\"failed to write json errors\");\n            out.flush().expect(\"failed to flush json errors\");\n        };\n    let lazy_msg = if lazy_stats.lazy_mode {\n        Some(format!(\n            \"The Flow server is currently in lazy mode and is only checking {}/{} files.\\nTo learn more, visit flow.org/en/docs/lang/lazy-modes\",\n            lazy_stats.checked_files, lazy_stats.total_files\n        ))\n    } else {\n        None\n    };\n    match response {\n        server_prot::response::StatusResponse::ERRORS {\n            errors,\n            warnings,\n            suppressed_errors,\n        } => {\n            let error_flags = &args.error_flags;\n            let from = flow_event_logger::get_from_i_am_a_clown();","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_cli/src/status_command.rs#L131-L167","documentation":"For `flow status --output-json`, the CLI writes the machine-readable error report to a locked stdout via flow_common_errors::error_utils::json_output::print_errors_with_offset_kind; this expect panics on the first write error. Rust ignores SIGPIPE, so a downstream JSON consumer that exits early (head, a crashing jq pipeline stage) surfaces here as ErrorKind::BrokenPipe.","triggerScenarios":"`flow status --output-json | jq '.errors' | head -3` where head quits early; a consumer parsing the JSON that exits on the first result; stdout redirected to a full disk; running with stdout closed.","commonSituations":"Editor/IDE plugins and CI scripts that consume only a prefix of the JSON status; full CI artifact disks; pipelines with early-terminating stages.","solutions":["Capture to a file first: `flow status --output-json > status.json`, then parse the file.","Make the consumer read the entire stream (replace head/grep -m with full parsers).","Free disk space for redirected output.","Maintainer fix: BrokenPipe → silent exit(0); other io errors → report."],"exampleFix":"// before\nflow_common_errors::error_utils::json_output::print_errors_with_offset_kind(/* ... */)\n    .expect(\"failed to write json errors\");\n\n// after\nif let Err(e) = flow_common_errors::error_utils::json_output::print_errors_with_offset_kind(/* ... */) {\n    if e.kind() == std::io::ErrorKind::BrokenPipe {\n        std::process::exit(0);\n    }\n    panic!(\"failed to write json errors: {}\", e);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = flow_common_errors::error_utils::json_output::print_errors_with_offset_kind(/* args */) {\n    if e.kind() == std::io::ErrorKind::BrokenPipe {\n        std::process::exit(0);\n    }\n    panic!(\"failed to write json errors: {}\", e);\n}","preventionTips":["Consume `flow status --output-json` via file capture, not early-exiting pipes.","Ensure downstream jq/python consumers read the whole stream.","Check disk space when redirecting JSON reports."],"tags":["stdout","broken-pipe","json","status-command","io-error","panic"],"backgroundTag":"broken-pipe","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}