kovidgoyal/kitty · warning

Ignoring modify_font with invalid size: {sz}

Error message

Ignoring modify_font with invalid size: {sz}

What it means

The size token of a modify_font directive (after stripping % or px suffix) could not be converted to float, so the directive is ignored.

Source

Thrown at kitty/options/utils.py:1118

    if mtype is ModificationType.size:
        font_name = parts[pos]
        pos += 1
    if plen - pos < 1:
        log_error(f'Ignoring invalid modify_font: {val}')
        return
    sz = parts[pos]
    pos += 1
    munit = ModificationUnit.pt
    if sz.endswith('%'):
        munit = ModificationUnit.percent
        sz = sz[:-1]
    elif sz.endswith('px'):
        munit = ModificationUnit.pixel
        sz = sz[:-2]
    try:
        mvalue = float(sz)
    except Exception:
        log_error(f'Ignoring modify_font with invalid size: {sz}')
        return
    key = mtype.name
    if font_name:
        key += f':{font_name}'
    yield key, FontModification(mtype, ModificationValue(mvalue, munit), font_name)


def env(val: str, current_val: dict[str, str]) -> Iterable[tuple[str, str]]:
    val = val.strip()
    if val:
        if '=' in val:
            key, v = val.split('=', 1)
            key, v = key.strip(), v.strip()
            if key:
                if v:
                    v = expandvars(v, current_val)
                yield key, v
        else:

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Use a plain number (pt), a number with px, or a percentage: '+2px', '110%', '5'.
  2. Remove unsupported unit suffixes.
  3. Check for stray unicode characters in the value.

Example fix

# before
modify_font size +2em

# after
modify_font size +2px
Defensive patterns

Strategy: validation

Validate before calling

def valid_size_token(sz: str) -> bool:
    core = sz[:-1] if sz.endswith('%') else sz[:-2] if sz.endswith('px') else sz
    try:
        float(core)
        return True
    except ValueError:
        return False

Type guard

def is_float_maybe_suffixed(sz: str) -> bool:
    for suf in ('%','px'):
        if sz.endswith(suf):
            sz = sz[:-len(suf)]
            break
    try:
        float(sz)
        return True
    except ValueError:
        return False

Prevention

When it happens

Trigger: 'modify_font size +2em', 'modify_font size abc', or a token that is only '%' with no number.

Common situations: Using unsupported CSS units (em, rem, pt suffix other than recognized bare pt); stray characters; localized decimal commas.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/f082272e6ef1b940. Report an issue: GitHub.