pola-rs/polars · error

failed to serialize the schema

Error message

failed to serialize the schema

What it means

After creating the file, `generate` serializes the DSL schema with `serde_json::to_writer_pretty` and expects success. A panic here means serde_json failed mid-write — typically an underlying I/O error while writing to the file, since the schema itself is serializable by construction.

Solutions

  1. Check free disk space and quota on the target filesystem.
  2. Re-run the command; transient I/O failures often clear on retry.
  3. If caused by schema data, update polars — serialization failures usually indicate a bug in a new node type's Schema implementation; file an issue.
Defensive patterns

Strategy: retry

Validate before calling

df -h . || true  # ensure adequate free space before generating
du -sh ./dsl-schema.json 2>/dev/null || true

Prevention

When it happens

Trigger: The output file/handle becomes unwritable during serialization (disk full, file closed/removed, I/O error on the underlying writer).

Common situations: Disk quota/full disk during schema generation in CI, network filesystem hiccups, or a schema type with a serde impl that fails on non-serializable data (e.g. NaN or map keys it can't serialize).

Understand the failure class

Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.

Related errors


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

Appendix: source

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

                update_hashes(path.unwrap_or(DEFAULT_HASHES_PATH.to_owned()));
            },
            "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();

View on GitHub (pinned to fe841f959e)