{"record":{"id":"78329fe97ffc059b","repo":"facebook/flow","slug":"failed-to-flush-json-errors-78329f","errorCode":null,"errorMessage":"failed to flush json errors","messagePattern":"failed to flush json errors","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_cli/src/status_command.rs","lineNumber":150,"sourceCode":"            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();\n            if args.output_json {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_cli/src/status_command.rs#L132-L168","documentation":"The flush of the JSON status output described in error 135. If the whole JSON report fits the stdio buffer, print_errors_with_offset_kind returns Ok without a syscall and this flush is where the closed pipe (BrokenPipe) or full disk (ENOSPC) is first detected — hence this is frequently the exact line that panics even though the 'write' expect just above never fired.","triggerScenarios":"`flow status --output-json | head -1` with a small report: buffered write succeeds, head exits, flush hits EPIPE; redirected output on a full filesystem.","commonSituations":"Small projects whose status JSON fits the pipe/socket buffer, piped into short-lived consumers in scripts; disk-full CI runners.","solutions":["Avoid early-exiting consumers; write to a file instead.","Keep the reader attached until flow exits.","Maintainer fix: on flush error, BrokenPipe → exit(0); otherwise report the io error."],"exampleFix":"// before\nout.flush().expect(\"failed to flush json errors\");\n\n// after\nif let Err(e) = out.flush() {\n    if e.kind() != std::io::ErrorKind::BrokenPipe {\n        panic!(\"failed to flush json 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        panic!(\"failed to flush json errors: {}\", e);\n    }\n    std::process::exit(0);\n}","preventionTips":["Small JSON reports buffer fully — the flush is where EPIPE appears; keep readers alive to the end.","Prefer file redirection for scripted status checks.","Avoid `| head` directly on flow status output."],"tags":["stdout","broken-pipe","flush","json","status-command","panic"],"backgroundTag":"broken-pipe","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}