{"record":{"id":"5212b9a85a5f9b64","repo":"pola-rs/polars","slug":"invalid-value-for-polars-csv-chunk-size-x","errorCode":null,"errorMessage":"invalid value for POLARS_CSV_CHUNK_SIZE: {x}","messagePattern":"invalid value for POLARS_CSV_CHUNK_SIZE: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-stream/src/nodes/io_sources/csv/mod.rs","lineNumber":227,"sourceCode":"            !(matches!(byte_source.as_ref(), &DynByteSource::Buffer(_)) && compression.is_none());\n\n        const ASSUMED_COMPRESSION_RATIO: usize = 4;\n        let decompressed_file_size_hint = match compression {\n            None => Some(file_size),\n            Some(_) => Some(file_size * ASSUMED_COMPRESSION_RATIO),\n        };\n\n        // Unify the two source options (uncompressed local file mmapp'ed, or streaming async with\n        // transparent decompression), into one unified reader source.\n        let reader_source = if use_async_prefetch {\n            // Prepare parameters for Prefetch task.\n            // TODO REFACTOR: use get_streaming_chunk_size(),\n            const DEFAULT_CSV_CHUNK_SIZE: usize = 32 * 1024 * 1024;\n            let memory_prefetch_func = get_memory_prefetch_func(verbose);\n            let chunk_size = std::env::var(\"POLARS_CSV_CHUNK_SIZE\")\n                .map(|x| {\n                    x.parse::<NonZeroUsize>()\n                        .unwrap_or_else(|_| panic!(\"invalid value for POLARS_CSV_CHUNK_SIZE: {x}\"))\n                        .get()\n                })\n                .unwrap_or(DEFAULT_CSV_CHUNK_SIZE);\n\n            let prefetch_limit = self\n                .chunk_prefetch_sync\n                .prefetch_limit\n                .min(file_size.div_ceil(chunk_size))\n                .max(1);\n\n            let (prefetch_send, prefetch_recv) = tokio::sync::mpsc::channel(prefetch_limit);\n\n            // Task: Prefetch.\n            // Initiate parallel downloads of raw chunks.\n            let byte_source = byte_source.clone();\n            let prefetch_task = {\n                let prefetch_semaphore = Arc::clone(&self.chunk_prefetch_sync.prefetch_semaphore);\n                let prefetch_prev_all_spawned =","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-stream/src/nodes/io_sources/csv/mod.rs#L209-L245","documentation":"Polars panics when the POLARS_CSV_CHUNK_SIZE environment variable is set but cannot be parsed as a non-zero usize. The streaming CSV source reads this variable at read start (begin_read) to size its read chunks; an unset variable falls back to the default 32 MiB chunk size, but a set-and-invalid value is a hard panic.","triggerScenarios":"Starting any streaming CSV scan (scan_csv in the streaming engine) with POLARS_CSV_CHUNK_SIZE set to an empty string, a non-numeric string (e.g. '32MB'), zero ('0'), a negative number, or a value exceeding usize range.","commonSituations":"Developer exports POLARS_CSV_CHUNK_SIZE=0 to 'disable' chunking, sets a human-readable value like '64m', leaves an empty value in a container env file, or copies a value with a trailing newline/space from docs.","solutions":["Set POLARS_CSV_CHUNK_SIZE to a plain positive integer, e.g. 33554432 (no units, no zero, no sign).","Unset the variable entirely (unset POLARS_CSV_CHUNK_SIZE or remove it from your env file) to use the default 32 MiB chunk size.","Check the actual value with `echo \"[$POLARS_CSV_CHUNK_SIZE]\"` for hidden whitespace or empty strings in shell profiles / container env files."],"exampleFix":"// before\nPOLARS_CSV_CHUNK_SIZE=32MB\n// after\nPOLARS_CSV_CHUNK_SIZE=33554432  # or unset entirely","handlingStrategy":"validation","validationCode":"const v = process.env.POLARS_CSV_CHUNK_SIZE;\nif (v !== undefined && (!/^\\d+$/.test(v.trim()) || BigInt(v.trim()) === 0n)) {\n  throw new Error(`POLARS_CSV_CHUNK_SIZE must be a positive integer, got: '${v}'`);\n}","typeGuard":"function isValidChunkSize(v) { return v === undefined || (/^\\d+$/.test(v.trim()) && Number(v.trim()) > 0); }","tryCatchPattern":"try {\n  runPolarsCsvScan();\n} catch (e) {\n  if (String(e).includes('POLARS_CSV_CHUNK_SIZE')) {\n    delete process.env.POLARS_CSV_CHUNK_SIZE; // fall back to default and retry\n    runPolarsCsvScan();\n  } else throw e;\n}","preventionTips":["Only set tuning env vars to bare positive integers, never with units or zero.","Keep such env vars out of shared shell rc / container base images.","Validate all POLARS_* env vars at process startup with a small check script."],"tags":["rust","env-var","csv","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"}