pola-rs/polars · error
invalid value for POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH
Error message
invalid value for POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH: {s} What it means
This panic fires when POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH is set to a value that either fails usize parsing or is less than 2. The variable controls how many consecutive runs of values the cloud writer coalesces into one contiguous chunk. Unlike a simple parse, this function also filters out values below 2, so both non-numeric and too-small values trigger the panic.
Solutions
- Set the variable to an integer >= 2 (e.g. 64) or unset it for the default
- If you intended to disable coalescing, remove the variable rather than setting it to 0 or 1
- Enable Polars verbose logging (POLARS_VERBOSE=1) to confirm the accepted value: it prints 'cloud_writer coalesce_run_length: <v>'
Example fix
// before POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH=1 // after POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH=32
Defensive patterns
Strategy: validation
Validate before calling
const v = process.env.POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH;
if (v !== undefined && !/^[0-9]+$/.test(v.trim())) throw new Error('must be an integer');
if (v !== undefined && parseInt(v, 10) < 2) throw new Error('POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH must be >= 2'); Type guard
function isValidCoalesceRunLength(v) { const n = parseInt(v, 10); return typeof v === 'string' && /^[0-9]+$/.test(v.trim()) && n >= 2; } Try / catch
// enforce the >= 2 floor before launch
const n = parseInt(process.env.POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH ?? '2', 10);
if (!Number.isInteger(n) || n < 2) { delete process.env.POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH; } Prevention
- Remember the minimum accepted value is 2, not 1
- Unset the variable to disable tuning rather than setting 0/1
- Enable POLARS_VERBOSE=1 to confirm resolved values
- Keep experimental tuning values out of committed .env files
When it happens
Trigger: export POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH=1 (rejected by the *x >= 2 filter), 0, 'abc', '2.5', or negative numbers; the panic occurs in cloud_writer_coalesce_run_length when a cloud writer buffers data (invoked via BytesBufferer/push_owned).
Common situations: Users experimenting with coalescing set the minimum sensible value as 1, not knowing the hard floor is 2; typos; leftover experimental settings in .env files.
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
- invalid value for POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE
- in-flight byte budget init must be larger than the…
- integer
- integer
- invalid `POLARS_MAX_CACHED_METADATA_SCANS` value
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/7212efa901644332.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-io/src/configs.rs:53
})
})
}
/// Runs of this many values whose total bytes are <= `copy_buffer_reserve_size` will be copied into
/// a single contiguous chunk.
pub(crate) fn cloud_writer_coalesce_run_length() -> usize {
return *COALESCE_RUN_LENGTH;
static COALESCE_RUN_LENGTH: LazyLock<usize> = LazyLock::new(|| {
let mut v: usize = 64;
if let Ok(s) = std::env::var("POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH") {
v = s
.parse::<usize>()
.ok()
.filter(|x| *x >= 2)
.unwrap_or_else(|| {
panic!("invalid value for POLARS_CLOUD_WRITER_COALESCE_RUN_LENGTH: {s}")
})
}
if polars_core::config::verbose() {
eprintln!("cloud_writer coalesce_run_length: {v}")
}
v
});
}
pub(crate) fn cloud_writer_copy_buffer_size() -> NonZeroUsize {
return *COPY_BUFFER_SIZE;
static COPY_BUFFER_SIZE: LazyLock<NonZeroUsize> = LazyLock::new(|| {
let mut v: NonZeroUsize = const { NonZeroUsize::new(16 * 1024 * 1024).unwrap() };
if let Ok(s) = std::env::var("POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE") {View on GitHub (pinned to fe841f959e)