{"record":{"id":"22dc1f3a279a55a2","repo":"pola-rs/polars","slug":"invalid-value-for-polars-force-ndjson-read-size","errorCode":null,"errorMessage":"invalid value for POLARS_FORCE_NDJSON_READ_SIZE: {x}","messagePattern":"invalid value for POLARS_FORCE_NDJSON_READ_SIZE: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-stream/src/nodes/io_sources/ndjson/line_batch_distributor.rs","lineNumber":141,"sourceCode":"    prev_leftover: Buffer<u8>,\n    read_size: usize,\n    chunk_idx: usize,\n    finished: bool,\n}\n\nimpl LineBatchProducer {\n    fn new(\n        mut reader: ByteSourceReader<ReaderSource>,\n        reverse: bool,\n        row_skipper: RowSkipper,\n        uncompressed_file_size_hint: Option<usize>,\n        use_prefetch_l2: bool,\n        verbose: bool,\n    ) -> PolarsResult<Self> {\n        let fixed_read_size = std::env::var(\"POLARS_FORCE_NDJSON_READ_SIZE\")\n            .map(|x| {\n                x.parse::<NonZeroUsize>().ok().unwrap_or_else(|| {\n                    panic!(\"invalid value for POLARS_FORCE_NDJSON_READ_SIZE: {x}\")\n                })\n            })\n            .ok();\n\n        let read_size = fixed_read_size\n            .map(NonZeroUsize::get)\n            .unwrap_or_else(ByteSourceReader::<ReaderSource>::initial_read_size);\n\n        if verbose {\n            eprintln!(\n                \"[NDJson LineBatchDistributor]: \\\n                n_rows_to_skip: {}, \\\n                reverse: {reverse}, \\\n                fixed_read_size: {fixed_read_size:?}\",\n                row_skipper.cfg_n_rows_to_skip,\n            );\n        }\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-stream/src/nodes/io_sources/ndjson/line_batch_distributor.rs#L123-L159","documentation":"Polars panics when POLARS_FORCE_NDJSON_READ_SIZE is set but cannot be parsed as a non-zero usize. The NDJSON line batch distributor reads it in new() to force a fixed read size (number of lines per batch); when unset or invalid-as-option it falls back to an automatically computed read size.","triggerScenarios":"Constructing a streaming NDJSON scan with the variable set to '', '0', '64k', or any string that fails NonZeroUsize parsing.","commonSituations":"Tuning NDJSON ingestion by copying values like '10K' or '1000 lines' from a blog post; the unit suffix and empty value are the common mistakes.","solutions":["Set the variable to a plain positive integer of lines, e.g. 10000.","Unset the variable so the read size is chosen automatically.","Check for unit suffixes ('K', 'lines') or surrounding whitespace in the exported value."],"exampleFix":"// before\nPOLARS_FORCE_NDJSON_READ_SIZE=10K\n// after\nPOLARS_FORCE_NDJSON_READ_SIZE=10000  # or unset","handlingStrategy":"validation","validationCode":"const v = process.env.POLARS_FORCE_NDJSON_READ_SIZE;\nif (v !== undefined && (!/^\\d+$/.test(v.trim()) || parseInt(v, 10) === 0)) {\n  throw new Error(`POLARS_FORCE_NDJSON_READ_SIZE must be a positive integer (lines), got: '${v}'`);\n}","typeGuard":"function isValidReadSize(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_FORCE_NDJSON_READ_SIZE')) {\n    delete process.env.POLARS_FORCE_NDJSON_READ_SIZE;\n    runNdjsonScan();\n  } else throw e;\n}","preventionTips":["The unit is lines — no 'K'/'lines' suffixes allowed.","Unset the variable to let the distributor compute the read size.","Add an env-var validation step to ingestion job entrypoints."],"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"}