{"record":{"id":"2944c22f396bf642","repo":"pola-rs/polars","slug":"invalid-polars-regex-size-limit","errorCode":null,"errorMessage":"invalid POLARS_REGEX_SIZE_LIMIT","messagePattern":"invalid POLARS_REGEX_SIZE_LIMIT","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-utils/src/regex_cache.rs","lineNumber":13,"sourceCode":"use std::cell::RefCell;\n\nuse regex::{Regex, RegexBuilder};\n\nuse crate::cache::LruCache;\n\nfn get_size_limit() -> Option<usize> {\n    Some(\n        std::env::var(\"POLARS_REGEX_SIZE_LIMIT\")\n            .ok()\n            .filter(|l| !l.is_empty())?\n            .parse()\n            .expect(\"invalid POLARS_REGEX_SIZE_LIMIT\"),\n    )\n}\n\n// Regex compilation is really heavy, and the resulting regexes can be large as\n// well, so we should have a good caching scheme.\n//\n// TODO: add larger global cache which has time-based flush.\n\n/// A cache for compiled regular expressions.\npub struct RegexCache {\n    cache: LruCache<String, Regex>,\n    size_limit: Option<usize>,\n}\n\nimpl RegexCache {\n    fn new() -> Self {\n        Self {\n            cache: LruCache::with_capacity(32),","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-utils/src/regex_cache.rs#L1-L31","documentation":"POLARS_REGEX_SIZE_LIMIT sets the regex crate's compiled-size limit for polars' LRU regex cache. get_size_limit() filters out empty values, then parses the remainder as usize; any non-empty, non-integer value fails to parse and this expect panics — at the latest when the first regex is compiled.","triggerScenarios":"Setting the variable to something like '10MB', '10_000_000' (underscores are not accepted by usize::from_str), or '-1', then using any regex feature (str.contains with regex, extract, replace) that initializes the RegexCache.","commonSituations":"Tuning memory limits with human-readable units; copying docker/compose env values with quotes or whitespace; regex-heavy ETL jobs where the panic only appears once a regex operation actually runs.","solutions":["Set a plain integer byte count: export POLARS_REGEX_SIZE_LIMIT=10485760","Unset the variable (or set it empty — empty is treated as unset) to use the default","Check for hidden whitespace or units in env files and container definitions","Validate tuning values in one place (deploy script) instead of ad hoc in each environment"],"exampleFix":"# before\nexport POLARS_REGEX_SIZE_LIMIT=10MB  # panic: invalid POLARS_REGEX_SIZE_LIMIT\n\n# after\nexport POLARS_REGEX_SIZE_LIMIT=10485760","handlingStrategy":"validation","validationCode":"import os\nv = os.environ.get(\"POLARS_REGEX_SIZE_LIMIT\")\nif v:  # empty is treated as unset\n    if not v.isdigit():\n        raise ValueError(\"POLARS_REGEX_SIZE_LIMIT must be an integer byte count\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use plain integers for byte limits (no MB suffixes, no underscores)","Unset the variable to fall back to the default","Exercise one regex operation in smoke tests so config errors surface at startup"],"tags":["environment-variable","regex","configuration","panic","rust"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}