pola-rs/polars · error
invalid value for POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE
Error message
invalid value for POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE: {s} What it means
This panic occurs when POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE is set but does not parse as a non-zero usize. The variable overrides the copy buffer size (default 16 MiB) used by the cloud writer when copying data into contiguous buffers. The value is read once inside a LazyLock, so the panic happens on first access during writer construction.
Solutions
- Set the variable to a plain positive integer of bytes (e.g. 33554432 for 32 MiB) or unset for the 16 MiB default
- Compute byte values yourself before exporting (no expressions or units accepted)
- Enable POLARS_VERBOSE=1 to see the resolved 'cloud_writer copy_buffer_size' at startup
Example fix
// before export POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE=32MB // after export POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE=33554432
Defensive patterns
Strategy: validation
Validate before calling
const v = process.env.POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE;
if (v !== undefined && !/^[0-9]+$/.test(v.trim())) throw new Error(`POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE must be a positive integer of bytes, got: ${v}`); Type guard
function isValidByteSize(v) { return typeof v === 'string' && /^[1-9][0-9]*$/.test(v.trim()); } Try / catch
// convert human sizes to bytes before export; reject anything else
const raw = process.env.POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE;
if (raw && !/^\d+$/.test(raw.trim())) { console.error('use plain bytes, e.g. 33554432'); process.exit(2); } Prevention
- Always express the value in raw bytes - no MB/GB suffixes or arithmetic
- Compute 32 * 1024 * 1024 in your shell before exporting
- Unset for the 16 MiB default
- Verify with POLARS_VERBOSE=1 at startup
When it happens
Trigger: export POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE=0, '16MB', '16*1024*1024', 'abc', or empty; triggered in cloud_writer_copy_buffer_size when the cloud writer is created (BytesBufferer::new).
Common situations: Appending unit suffixes like MB/GB out of habit; arithmetic expressions that shells do not evaluate; a container image with a malformed tuned value; mistaking it for a knob that accepts 0 to disable buffering.
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_COALESCE_RUN_LENGTH
- 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/32a37755204199f0.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-io/src/configs.rs:73
}
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") {
v = s.parse::<NonZeroUsize>().unwrap_or_else(|_| {
panic!("invalid value for POLARS_CLOUD_WRITER_COPY_BUFFER_SIZE: {s}")
})
}
if polars_core::config::verbose() {
eprintln!("cloud_writer copy_buffer_size: {v}")
}
v
});
}
/// Tail size to speculatively fetch when reading file metadata from a cloud source. Sized
/// generously as the cost of overfetching is low (extra KB) vs the cost of underfetching
/// (extra round-trip).
pub const DEFAULT_CLOUD_FOOTER_READ_SIZE: usize = 256 * 1024;
// Not cached - lookup cost is low compared to I/O, allows for testing.
pub fn cloud_footer_read_size() -> usize {View on GitHub (pinned to fe841f959e)