{"record":{"id":"3133c2f66de2d902","repo":"pola-rs/polars","slug":"invalid-value-for-polars-ndjson-chunk-size-x","errorCode":null,"errorMessage":"invalid value for POLARS_NDJSON_CHUNK_SIZE: {x}","messagePattern":"invalid value for POLARS_NDJSON_CHUNK_SIZE: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-stream/src/nodes/io_sources/ndjson/mod.rs","lineNumber":430,"sourceCode":"        let row_skipper = RowSkipper {\n            cfg_n_rows_to_skip: n_rows_to_skip,\n            n_rows_skipped: 0,\n            is_line: self.chunk_reader_builder.is_line_fn(),\n            reverse: is_negative_slice,\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_NDJSON_CHUNK_SIZE: usize = 32 * 1024 * 1024;\n            let memory_prefetch_func = get_memory_prefetch_func(verbose);\n            let chunk_size = std::env::var(\"POLARS_NDJSON_CHUNK_SIZE\")\n                .map(|x| {\n                    x.parse::<NonZeroUsize>()\n                        .unwrap_or_else(|_| {\n                            panic!(\"invalid value for POLARS_NDJSON_CHUNK_SIZE: {x}\")\n                        })\n                        .get()\n                })\n                .unwrap_or(DEFAULT_NDJSON_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 data chunks.\n            let byte_source = byte_source.clone();\n            let prefetch_task = {\n                let prefetch_semaphore = Arc::clone(&self.chunk_prefetch_sync.prefetch_semaphore);","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-stream/src/nodes/io_sources/ndjson/mod.rs#L412-L448","documentation":"Polars panics when the POLARS_NDJSON_CHUNK_SIZE environment variable is set but cannot be parsed as a non-zero usize. This variable controls the chunk size (in bytes) used when reading newline-delimited JSON files in the streaming engine; it defaults to 32 MiB. The panic happens in begin_read when parsing the user-provided value fails or the value is zero.","triggerScenarios":"Setting POLARS_NDJSON_CHUNK_SIZE to a non-numeric string (e.g. '32mb'), a negative number, a zero value ('0'), or an integer larger than usize::MAX, then starting an NDJSON scan with scan_nd_json / pl.scan_ndjson in the streaming engine.","commonSituations":"Users copy tuning advice and include units like '32M' or '33554432b', set the value in a shell profile with quotes/whitespace, or set it to 0 thinking it means 'unlimited'. Non-ASCII or invisible characters (BOM, trailing newline in dotenv files) also break parsing.","solutions":["Unset POLARS_NDJSON_CHUNK_SIZE to fall back to the 32 MiB default","Set it to a plain positive decimal integer without units or spaces, e.g. export POLARS_NDJSON_CHUNK_SIZE=33554432","Ensure the value is non-zero and fits in a usize (max 2^64-1 on 64-bit platforms)"],"exampleFix":"// before\nexport POLARS_NDJSON_CHUNK_SIZE=32mb\n// after\nexport POLARS_NDJSON_CHUNK_SIZE=33554432","handlingStrategy":"validation","validationCode":"// Rust: validate before launching\nif let Ok(v) = std::env::var(\"POLARS_NDJSON_CHUNK_SIZE\") {\n    assert!(v.parse::<NonZeroUsize>().is_ok(), \"POLARS_NDJSON_CHUNK_SIZE must be a positive integer, got: {v}\");\n}","typeGuard":"fn valid_chunk_size(v: &str) -> bool { v.parse::<NonZeroUsize>().is_ok() }","tryCatchPattern":null,"preventionTips":["Never include unit suffixes or spaces in POLARS_* numeric env vars","Validate env config in CI before running Polars jobs","Prefer leaving the variable unset unless tuning is required"],"tags":["rust","environment-variable","configuration","polars"],"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"}