pola-rs/polars · error

invalid value for POLARS_UPLOAD_CHUNK_SIZE

Error message

invalid value for POLARS_UPLOAD_CHUNK_SIZE: {s}

What it means

This is a panic (process abort) thrown when the environment variable POLARS_UPLOAD_CHUNK_SIZE is set but cannot be parsed as a non-zero usize. Polars reads this variable in env_upload_chunk_size to configure the upload chunk size for cloud writers. Any value that is empty, non-numeric, negative, or zero causes an immediate panic instead of returning an error, because the value is expected to be valid configuration.

Solutions

  1. Set POLARS_UPLOAD_CHUNK_SIZE to a plain positive integer (e.g. 8388608), or unset it entirely to use the built-in default
  2. Verify the value parses: cargo eval or `echo $POLARS_UPLOAD_CHUNK_SIZE` and ensure it matches ^[0-9]+$ and is >= 1
  3. Check CI/CD templating and .env files for empty or malformed values being injected into the variable

Example fix

// before
export POLARS_UPLOAD_CHUNK_SIZE=4MB
// after
export POLARS_UPLOAD_CHUNK_SIZE=4194304
Defensive patterns

Strategy: validation

Validate before calling

const v = process.env.POLARS_UPLOAD_CHUNK_SIZE;
if (v !== undefined && !/^[0-9]+$/.test(v.trim())) throw new Error(`POLARS_UPLOAD_CHUNK_SIZE must be a positive integer, got: ${v}`);

Type guard

function isValidChunkSize(v) { return typeof v === 'string' && /^[0-9]+$/.test(v.trim()) && parseInt(v, 10) > 0; }

Try / catch

// panic cannot be caught from the host language; fix the env value before launch
try { runPolarsJob(); } catch (e) { if (/invalid value for POLARS_UPLOAD_CHUNK_SIZE/.test(String(e))) console.error('Fix POLARS_UPLOAD_CHUNK_SIZE: positive integer required'); throw e; }

Prevention

When it happens

Trigger: Setting POLARS_UPLOAD_CHUNK_SIZE to a value that fails NonZeroUsize::parse, e.g. export POLARS_UPLOAD_CHUNK_SIZE=0, POLARS_UPLOAD_CHUNK_SIZE=abc, POLARS_UPLOAD_CHUNK_SIZE=-100, POLARS_UPLOAD_CHUNK_SIZE=1e6, or POLARS_UPLOAD_CHUNK_SIZE=" 1024" (whitespace). The panic fires the first time env_upload_chunk_size is consulted during cloud/remote file IO.

Common situations: Copy-pasted config with a typo; setting the variable to 0 believing it means 'unlimited' or 'default'; adding unit suffixes like '4MB' or '1_000_000'; shell quoting whitespace; CI/CD templating that injects an empty string.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


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

Appendix: source

Thrown at crates/polars-io/src/configs.rs:7

use std::num::NonZeroUsize;
use std::sync::LazyLock;

pub fn env_upload_chunk_size() -> Option<NonZeroUsize> {
    std::env::var("POLARS_UPLOAD_CHUNK_SIZE").ok().map(|s| {
        s.parse::<NonZeroUsize>()
            .unwrap_or_else(|_| panic!("invalid value for POLARS_UPLOAD_CHUNK_SIZE: {s}"))
    })
}

pub fn env_partitioned_upload_chunk_size() -> Option<NonZeroUsize> {
    std::env::var("POLARS_PARTITIONED_UPLOAD_CHUNK_SIZE")
        .ok()
        .map(|s| {
            s.parse::<NonZeroUsize>().unwrap_or_else(|_| {
                panic!("invalid value for POLARS_PARTITIONED_UPLOAD_CHUNK_SIZE: {s}")
            })
        })
}

/// Max concurrent tasks within a single cloud writer.
pub fn env_upload_concurrency() -> Option<NonZeroUsize> {
    std::env::var("POLARS_UPLOAD_CONCURRENCY").ok().map(|s| {
        s.parse::<NonZeroUsize>()
            .unwrap_or_else(|_| panic!("invalid value for POLARS_UPLOAD_CONCURRENCY: {s}"))

View on GitHub (pinned to fe841f959e)