{"record":{"id":"22d365587af0afe3","repo":"pola-rs/polars","slug":"table-width-argument-does-not-fit-in-u16","errorCode":null,"errorMessage":"table width argument does not fit in u16","messagePattern":"table width argument does not fit in u16","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/fmt.rs","lineNumber":751,"sourceCode":"                        } else {\n                            break;\n                        }\n                    }\n                }\n            } else if height > 0 {\n                let dots: Vec<String> = vec![ellipsis; self.width()];\n                table.add_row(dots);\n            }\n            let tbl_fallback_width = 100;\n            let tbl_width = std::env::var(\"POLARS_TABLE_WIDTH\")\n                .map(|s| {\n                    let n = s\n                        .parse::<i64>()\n                        .expect(\"could not parse table width argument\");\n                    let w = if n < 0 {\n                        u16::MAX\n                    } else {\n                        u16::try_from(n).expect(\"table width argument does not fit in u16\")\n                    };\n                    Some(w)\n                })\n                .unwrap_or(None);\n\n            // column width constraints\n            let col_width_exact =\n                |w: usize| ColumnConstraint::Absolute(comfy_table::Width::Fixed(w as u16));\n            let col_width_bounds = |l: usize, u: usize| ColumnConstraint::Boundaries {\n                lower: Width::Fixed(l as u16),\n                upper: Width::Fixed(u as u16),\n            };\n            let min_col_width = std::cmp::max(5, 3 + padding);\n            for (idx, elem_len) in max_elem_lengths.iter().enumerate() {\n                let mx = std::cmp::min(\n                    str_truncate + ellipsis_len + padding,\n                    std::cmp::max(name_lengths[idx], *elem_len),\n                );","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/fmt.rs#L733-L769","documentation":"When rendering a table, Polars reads the POLARS_FMT_TBL_WIDTH environment variable and parses it as i64, then converts it to u16 for internal width handling. The panic fires when the parsed value does not fit in a u16 (i.e. it is greater than 65535; negative values are mapped to u16::MAX and never reach this check). This means the configured display width exceeds the maximum the formatter supports.","triggerScenarios":"Setting POLARS_FMT_TBL_WIDTH to a value > 65535 (e.g. 1000000) before running a program or test that prints a DataFrame with `fmt`/`Display`.","commonSituations":"Users exporting a shell config with a huge table-width value assuming it means 'unlimited'; CI scripts that set the env var dynamically from a terminal-width calculation that returns a large number; typos like an extra digit in the value.","solutions":["Set POLARS_FMT_TBL_WIDTH to a value between 0 and 65535.","Unset POLARS_FMT_TBL_WIDTH to fall back to the default width behavior.","If unlimited width is intended, remove negative/huge sentinels and rely on the default or u16::MAX-equivalent values the formatter already treats as very wide."],"exampleFix":"// before\nexport POLARS_FMT_TBL_WIDTH=999999\n\n// after\nexport POLARS_FMT_TBL_WIDTH=200","handlingStrategy":"validation","validationCode":"let v: i64 = std::env::var(\"POLARS_FMT_TBL_WIDTH\")?.parse()?;\nassert!((0..=u16::MAX as i64).contains(&v), \"POLARS_FMT_TBL_WIDTH must be 0..=65535\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp POLARS_FMT_TBL_WIDTH to 65535 in shell profiles/CI setup scripts.","Sanitize terminal-width-derived values before exporting them."],"tags":["rust","polars","formatting","env-var","value-out-of-range"],"backgroundTag":"value-out-of-range","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"}