kovidgoyal/kitty · error · ValueError
Not a number: {x} with error: {e}
Error message
Not a number: {x} with error: {e} What it means
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.
Source
Thrown at kitty/conf/utils.py:78
def to_color_or_none(x: str) -> Color | None:
return None if x.lower() == 'none' else to_color(x)
def unit_float(x: ConvertibleToNumbers) -> float:
return max(0, min(float(x), 1))
def signed_unit_float(x: ConvertibleToNumbers) -> float:
return max(-1, min(float(x), 1))
def number_with_unit(x: str, default_unit: str, *extra_units: str) -> tuple[float, str]:
if (mat := number_unit_pat.match(x)) is not None:
try:
value = float(mat.group(1))
except Exception as e:
raise ValueError(f'Not a number: {x} with error: {e}')
unit = mat.group(2) or default_unit
if unit != default_unit and unit not in extra_units:
raise ValueError(f'Not a valid unit: {x}. Allowed units are: {default_unit}, {", ".join(extra_units)}')
return value, unit
raise ValueError(f'Invalid number with unit: {x}')
def to_bool(x: str) -> bool:
return x.lower() in ('y', 'yes', 'true')
class ToCmdline:
def __init__(self) -> None:
self.override_env: dict[str, str] | None = None
def __enter__(self) -> 'ToCmdline':
return self
View on GitHub (pinned to 6d5d0c4406)
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
Example fix
# before text_fg_override_threshold 1e999px # after text_fg_override_threshold 20
Defensive patterns
Strategy: validation
Validate before calling
import re ok = re.fullmatch(r'[+-]?(\d+\.?\d*|\.\d+)([a-z]*)', value.strip()) is not None
Try / catch
try:
v, u = number_with_unit(x, 'px')
except ValueError as e:
v, u = default_value, 'px' Prevention
- Use plain decimal numbers in config values
- Validate numeric config strings before writing kitty.conf
When it happens
Trigger: 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).
Common situations: Hand-edited kitty.conf with unusual numeric spellings; programmatic config generation producing inf/nan.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Invalid number with unit: {x}
- Not a valid unit: {x}. Allowed units are: {default_unit}, {"
- Unknown key action: {action}
- This should be run as kitten broadcast
- No option named: {k}
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/52838730a2447a28.
Report an issue: GitHub.