pola-rs/polars · error

failed to flush the schema file

Error message

failed to flush the schema file

What it means

`generate` finishes with `file.flush()` and expects success. A panic here means buffered data could not be pushed to the underlying file — an I/O error such as disk-full, device error, or a closed/invalid handle.

Solutions

  1. Check and free disk space, then regenerate the schema file.
  2. Inspect the panic's io::Error message for the OS-level cause (ENOSPC, EIO, etc.).
  3. Re-run `dsl-schema generate` after fixing storage; delete a partially-written output file first.
Defensive patterns

Strategy: retry

Validate before calling

free_kb=$(df -k --output=avail . | tail -1)
[ "$free_kb" -gt 10240 ] || { echo "disk nearly full" >&2; exit 1; }

Prevention

When it happens

Trigger: flush() returning Err because the OS write failed (ENOSPC, EIO) after the JSON and newline writes were buffered.

Common situations: Running out of disk space at the very end of generation; failing storage devices; container filesystem limits hit during CI schema regeneration.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/403a74483cfdc77a. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-plan/src/bin/dsl-schema.rs:80

            "check-hashes" => {
                check_hashes(path.unwrap_or(DEFAULT_HASHES_PATH.to_owned()));
            },
            unknown => {
                panic!("unknown command: `{unknown}`");
            },
        }
    }

    /// Serializes the current DSL schema into a file at the given path.
    ///
    /// Any existing file at the path is overwritten.
    fn generate(path: impl AsRef<Path>) {
        let schema = DslPlan::dsl_schema();

        let mut file = File::create(path).expect("failed to open the schema file for writing");
        serde_json::to_writer_pretty(&mut file, &schema).expect("failed to serialize the schema");
        writeln!(&mut file).expect("failed to write the last newline");
        file.flush().expect("failed to flush the schema file");
    }

    /// Outputs the current DSL schema hashes into a file at the given path.
    ///
    /// Any existing file at the path is overwritten.
    fn update_hashes(path: impl AsRef<Path>) {
        std::fs::write(path, current_schema_hashes())
            .expect("failed to write the schema into the file");
        eprintln!("the DSL schema file was updated");
    }

    /// Checks that the current schema hashes match the schema hashes in the file.
    fn check_hashes(path: impl AsRef<Path>) {
        let file_hashes =
            std::fs::read_to_string(path).expect("failed to read the schema hashes from the file");
        let expected = current_schema_hashes();
        if file_hashes != expected {
            eprintln!("the schema hashes are not up to date, run `make update-dsl-schema-hashes`");

View on GitHub (pinned to fe841f959e)