pola-rs/polars · error
invalid value for POLARS_LINES_CHUNK_PREFETCH_LIMIT
Error message
invalid value for POLARS_LINES_CHUNK_PREFETCH_LIMIT: {x} What it means
Polars panics when POLARS_LINES_CHUNK_PREFETCH_LIMIT is set but not a valid non-zero usize. The lines (text) source reads it in set_execution_state to bound how many chunks are prefetched concurrently; the default is 2x the number of pipelines, clamped to at least 1.
Solutions
- Set the variable to a plain positive integer (e.g. 8).
- Unset it to get the default 2*num_pipelines prefetch limit.
- Search dotfiles and deployment manifests for stale/empty definitions of this variable.
Example fix
// before POLARS_LINES_CHUNK_PREFETCH_LIMIT=0 // after POLARS_LINES_CHUNK_PREFETCH_LIMIT=8 # or unset
Defensive patterns
Strategy: validation
Validate before calling
const v = process.env.POLARS_LINES_CHUNK_PREFETCH_LIMIT;
if (v !== undefined && (!/^\d+$/.test(v.trim()) || parseInt(v, 10) === 0)) {
throw new Error(`POLARS_LINES_CHUNK_PREFETCH_LIMIT must be a positive integer, got: '${v}'`);
} Type guard
function isValidPrefetchLimit(v) { return v === undefined || (/^\d+$/.test(v.trim()) && Number(v.trim()) > 0); } Try / catch
try {
runLinesScan();
} catch (e) {
if (String(e).includes('POLARS_LINES_CHUNK_PREFETCH_LIMIT')) {
delete process.env.POLARS_LINES_CHUNK_PREFETCH_LIMIT;
runLinesScan();
} else throw e;
} Prevention
- Treat 0 and empty string as invalid — unset instead.
- Avoid fractional values; the parser accepts usize only.
- Audit CI env blocks where this variable may be exported empty.
When it happens
Trigger: Reading plain-text/lines files (read_lines / streaming lines source) with the env var set to '', '0', 'abc', or a number larger than usize::MAX.
Common situations: A leftover export from tuning experiments, an empty value in a Kubernetes manifest env entry, or a fractional value like '2.5'.
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_CSV_CHUNK_SIZE
- invalid value for POLARS_FORCE_NDJSON_READ_SIZE
- invalid value for POLARS_MAX_CONCURRENT_SCANS
- invalid value for POLARS_NDJSON_CHUNK_PREFETCH_LIMIT
- invalid value for POLARS_NUM_READERS_PRE_INIT
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/9140a7ea2a9a7774.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-stream/src/nodes/io_sources/lines.rs:54
}
impl FileReaderBuilder for LineReaderBuilder {
fn reader_name(&self) -> &str {
"line"
}
fn reader_capabilities(&self) -> ReaderCapabilities {
ndjson_reader_capabilities()
}
fn set_execution_state(&self, execution_state: &crate::execute::StreamingExecutionState) {
// The maximum number of chunks actively being prefetched at any point in time.
let prefetch_limit = std::env::var("POLARS_LINES_CHUNK_PREFETCH_LIMIT")
.map(|x| {
x.parse::<NonZeroUsize>()
.ok()
.unwrap_or_else(|| {
panic!("invalid value for POLARS_LINES_CHUNK_PREFETCH_LIMIT: {x}")
})
.get()
})
.unwrap_or(execution_state.num_pipelines.saturating_mul(2))
.max(1);
self.prefetch_limit.store(prefetch_limit);
if config::verbose() {
eprintln!(
"[LineReaderBuilder]: prefetch_limit: {}",
self.prefetch_limit.load()
);
}
self.prefetch_semaphore
.set(Arc::new(tokio::sync::Semaphore::new(prefetch_limit)))
.unwrap()View on GitHub (pinned to fe841f959e)