{"record":{"id":"7f26c5f6d65ae0f4","repo":"pola-rs/polars","slug":"invalid-value-for-polars-ndjson-chunk-prefetch-lim","errorCode":null,"errorMessage":"invalid value for POLARS_NDJSON_CHUNK_PREFETCH_LIMIT: {x}","messagePattern":"invalid value for POLARS_NDJSON_CHUNK_PREFETCH_LIMIT: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-stream/src/nodes/io_sources/ndjson/builder.rs","lineNumber":59,"sourceCode":"\n#[cfg(feature = \"json\")]\nimpl FileReaderBuilder for NDJsonReaderBuilder {\n    fn reader_name(&self) -> &str {\n        \"ndjson\"\n    }\n\n    fn reader_capabilities(&self) -> ReaderCapabilities {\n        ndjson_reader_capabilities()\n    }\n\n    fn set_execution_state(&self, execution_state: &crate::execute::StreamingExecutionState) {\n        // The maximum number of chunks actively being prefetched at any given point in time.\n        let prefetch_limit = std::env::var(\"POLARS_NDJSON_CHUNK_PREFETCH_LIMIT\")\n            .map(|x| {\n                x.parse::<NonZeroUsize>()\n                    .ok()\n                    .unwrap_or_else(|| {\n                        panic!(\"invalid value for POLARS_NDJSON_CHUNK_PREFETCH_LIMIT: {x}\")\n                    })\n                    .get()\n            })\n            .unwrap_or(execution_state.num_pipelines.saturating_mul(2))\n            .max(1);\n\n        self.prefetch_limit.store(prefetch_limit);\n\n        if config::verbose() {\n            eprintln!(\n                \"[NDJsonReaderBuilder]: prefetch_limit: {}\",\n                self.prefetch_limit.load()\n            );\n        }\n\n        self.prefetch_semaphore\n            .set(Arc::new(tokio::sync::Semaphore::new(prefetch_limit)))\n            .unwrap()","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-stream/src/nodes/io_sources/ndjson/builder.rs#L41-L77","documentation":"Polars panics when POLARS_NDJSON_CHUNK_PREFETCH_LIMIT is set but cannot be parsed as a non-zero usize. The NDJSON source builder reads it in set_execution_state to cap concurrently prefetched chunks; the default is 2x num_pipelines, clamped to at least 1.","triggerScenarios":"Streaming scan_ndjson with the variable set to '', '0', 'auto', or a value exceeding usize range.","commonSituations":"Users copy env settings between Polars versions or set '0' attempting to disable prefetch, both of which fail the NonZeroUsize parse.","solutions":["Set the variable to a plain positive integer (e.g. 4).","Unset the variable to use the default 2*num_pipelines limit.","Grep shell profiles and container configs for stale/invalid values of this variable."],"exampleFix":"// before\nPOLARS_NDJSON_CHUNK_PREFETCH_LIMIT=auto\n// after\nPOLARS_NDJSON_CHUNK_PREFETCH_LIMIT=4  # or unset","handlingStrategy":"validation","validationCode":"const v = process.env.POLARS_NDJSON_CHUNK_PREFETCH_LIMIT;\nif (v !== undefined && (!/^\\d+$/.test(v.trim()) || parseInt(v, 10) === 0)) {\n  throw new Error(`POLARS_NDJSON_CHUNK_PREFETCH_LIMIT must be a positive integer, got: '${v}'`);\n}","typeGuard":"function isValidNdjsonPrefetch(v) { return v === undefined || (/^\\d+$/.test(v.trim()) && Number(v.trim()) > 0); }","tryCatchPattern":"try {\n  runNdjsonScan();\n} catch (e) {\n  if (String(e).includes('POLARS_NDJSON_CHUNK_PREFETCH_LIMIT')) {\n    delete process.env.POLARS_NDJSON_CHUNK_PREFETCH_LIMIT;\n    runNdjsonScan();\n  } else throw e;\n}","preventionTips":["Don't attempt to 'disable' prefetch with 0 — unset instead.","Keep numeric tuning env vars consistent across environments.","Run a smoke scan in CI with the same env vars as production."],"tags":["rust","env-var","ndjson","config"],"backgroundTag":"invalid-env-var-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}