{"record":{"id":"06bfb04967b025c2","repo":"facebook/flow","slug":"failed-to-flush-stdout","errorCode":null,"errorMessage":"failed to flush stdout","messagePattern":"failed to flush stdout","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_cli/src/save_state_command.rs","lineNumber":89,"sourceCode":"            )\n        }\n        (Some(true), None) => server_prot::request::SaveStateOut::Scm,\n        (_, Some(out)) => server_prot::request::SaveStateOut::File(std::path::PathBuf::from(\n            flow_common::files::imaginary_realpath(&out),\n        )),\n    };\n\n    let request = server_prot::request::Command::SAVE_STATE { out };\n    let response =\n        command_utils::connect_and_make_request(&flowconfig_name, &connect_flags, &root, &request);\n    match response {\n        server_prot::response::Response::SAVE_STATE(Err(msg)) => {\n            eprintln!(\"{}\", msg);\n            flow_common_exit_status::exit(flow_common_exit_status::FlowExitStatus::UnknownError)\n        }\n        server_prot::response::Response::SAVE_STATE(Ok(msg)) => {\n            println!(\"{}\", msg);\n            std::io::stdout().flush().expect(\"failed to flush stdout\");\n        }\n        response => command_utils::failwith_bad_response(&request, &response),\n    }\n}\n\npub(crate) fn command() -> command_spec::Command {\n    command_spec::command(spec(), main)\n}\n","sourceCodeStart":71,"sourceCodeEnd":98,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_cli/src/save_state_command.rs#L71-L98","documentation":"`flow save-state` sends a SAVE_STATE request to the server; on success it prints the server's confirmation message and flushes stdout. The saved state was already written server-side before this point, so a panic here does not mean the save failed — only that printing the confirmation to a dead or full stdout failed (BrokenPipe / ENOSPC), and the expect turns that into a crash with a nonzero exit code.","triggerScenarios":"`flow save-state | head -c 10` (consumer exits after a few bytes); stdout redirected to a full filesystem; stdout fd closed (`>&-`); a scripting wrapper that stops reading flow's output once it sees the first bytes.","commonSituations":"Automation piping save-state output through short-reading consumers; CI disks at capacity; wrapper scripts that discard output early.","solutions":["Run `flow save-state` without piping into short-lived consumers, or redirect to a file with free space.","Check disk space on the redirect target.","Verify the save actually succeeded via the server (server logs / subsequent load) — the panic is only about printing the message.","Maintainer fix: treat BrokenPipe on the final flush as success and exit 0."],"exampleFix":"// before\nprintln!(\"{}\", msg);\nstd::io::stdout().flush().expect(\"failed to flush stdout\");\n\n// after\nprintln!(\"{}\", msg);\nif let Err(e) = std::io::stdout().flush() {\n    if e.kind() != std::io::ErrorKind::BrokenPipe {\n        panic!(\"failed to flush stdout: {}\", e);\n    }\n    // reader went away; the save-state already succeeded\n    std::process::exit(0);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"println!(\"{}\", msg);\nif let Err(e) = std::io::stdout().flush() {\n    if e.kind() != std::io::ErrorKind::BrokenPipe {\n        panic!(\"failed to flush stdout: {}\", e);\n    }\n    std::process::exit(0); // save-state already succeeded server-side\n}","preventionTips":["Do not pipe save-state output into consumers that stop reading early.","Redirect to a file with free space when capturing output.","Remember the save completes server-side even if this print fails — verify server-side before assuming failure."],"tags":["stdout","broken-pipe","flush","save-state","panic"],"backgroundTag":"broken-pipe","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}