{"record":{"id":"52838730a2447a28","repo":"kovidgoyal/kitty","slug":"not-a-number-x-with-error-e","errorCode":null,"errorMessage":"Not a number: {x} with error: {e}","messagePattern":"Not a number: (.+?) with error: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"kitty/conf/utils.py","lineNumber":78,"sourceCode":"\ndef to_color_or_none(x: str) -> Color | None:\n    return None if x.lower() == 'none' else to_color(x)\n\n\ndef unit_float(x: ConvertibleToNumbers) -> float:\n    return max(0, min(float(x), 1))\n\n\ndef signed_unit_float(x: ConvertibleToNumbers) -> float:\n    return max(-1, min(float(x), 1))\n\n\ndef number_with_unit(x: str, default_unit: str, *extra_units: str) -> tuple[float, str]:\n    if (mat := number_unit_pat.match(x)) is not None:\n        try:\n            value = float(mat.group(1))\n        except Exception as e:\n            raise ValueError(f'Not a number: {x} with error: {e}')\n        unit = mat.group(2) or default_unit\n        if unit != default_unit and unit not in extra_units:\n            raise ValueError(f'Not a valid unit: {x}. Allowed units are: {default_unit}, {\", \".join(extra_units)}')\n        return value, unit\n    raise ValueError(f'Invalid number with unit: {x}')\n\n\ndef to_bool(x: str) -> bool:\n    return x.lower() in ('y', 'yes', 'true')\n\n\nclass ToCmdline:\n    def __init__(self) -> None:\n        self.override_env: dict[str, str] | None = None\n\n    def __enter__(self) -> 'ToCmdline':\n        return self\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/conf/utils.py#L60-L96","documentation":"conf.utils.number_with_unit parses strings like '10px'/'3col'; if the numeric part matches the regex but float() fails, it raises ValueError('Not a number: ...'). This is a config-value parser used for e.g. text_fg_override_threshold-style options.","triggerScenarios":"A config value whose number portion is malformed such that regex matches but float conversion throws (extremely large numbers, NaN-like strings depending on the pattern).","commonSituations":"Hand-edited kitty.conf with unusual numeric spellings; programmatic config generation producing inf/nan.","solutions":["Use a plain decimal number, optionally with a valid unit","Regenerate/normalize the config value programmatically","Check for stray characters pasted into the number"],"exampleFix":"# before\ntext_fg_override_threshold 1e999px\n# after\ntext_fg_override_threshold 20","handlingStrategy":"validation","validationCode":"import re\nok = re.fullmatch(r'[+-]?(\\d+\\.?\\d*|\\.\\d+)([a-z]*)', value.strip()) is not None","typeGuard":null,"tryCatchPattern":"try:\n    v, u = number_with_unit(x, 'px')\nexcept ValueError as e:\n    v, u = default_value, 'px'","preventionTips":["Use plain decimal numbers in config values","Validate numeric config strings before writing kitty.conf"],"tags":["kitty","config","number-parsing","valueerror"],"backgroundTag":"invalid-config-value","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}