facebook/flow · error

failed to flush json errors

Error message

failed to flush json errors

What it means

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.

Source

Thrown at rust_port/crates/flow_cli/src/status_command.rs:150

            let strip_root = strip_root
                .as_deref()
                .map(|root| root.to_string_lossy().into_owned());
            let stdout = std::io::stdout();
            let mut out = stdout.lock();
            flow_common_errors::error_utils::json_output::print_errors_with_offset_kind(
                &mut out,
                strip_root.as_deref(),
                suppressed_errors,
                args.pretty,
                args.output_json_version
                    .unwrap_or(json_output::JsonVersion::JsonV1),
                &None,
                offset_kind,
                errors,
                warnings,
            )
            .expect("failed to write json errors");
            out.flush().expect("failed to flush json errors");
        };
    let lazy_msg = if lazy_stats.lazy_mode {
        Some(format!(
            "The Flow server is currently in lazy mode and is only checking {}/{} files.\nTo learn more, visit flow.org/en/docs/lang/lazy-modes",
            lazy_stats.checked_files, lazy_stats.total_files
        ))
    } else {
        None
    };
    match response {
        server_prot::response::StatusResponse::ERRORS {
            errors,
            warnings,
            suppressed_errors,
        } => {
            let error_flags = &args.error_flags;
            let from = flow_event_logger::get_from_i_am_a_clown();
            if args.output_json {

View on GitHub (pinned to f88ac94bcf)

Solutions

  1. Avoid early-exiting consumers; write to a file instead.
  2. Keep the reader attached until flow exits.
  3. Maintainer fix: on flush error, BrokenPipe → exit(0); otherwise report the io error.

Example fix

// before
out.flush().expect("failed to flush json errors");

// after
if let Err(e) = out.flush() {
    if e.kind() != std::io::ErrorKind::BrokenPipe {
        panic!("failed to flush json errors: {}", e);
    }
    std::process::exit(0);
}
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = out.flush() {
    if e.kind() != std::io::ErrorKind::BrokenPipe {
        panic!("failed to flush json errors: {}", e);
    }
    std::process::exit(0);
}

Prevention

When it happens

Trigger: `flow status --output-json | head -1` with a small report: buffered write succeeds, head exits, flush hits EPIPE; redirected output on a full filesystem.

Common situations: Small projects whose status JSON fits the pipe/socket buffer, piped into short-lived consumers in scripts; disk-full CI runners.

Related errors


AI-assisted analysis of facebook/flow@f88ac94bcf (2026-08-20). Data as JSON: /api/errors/78329fe97ffc059b. Report an issue: GitHub.