kovidgoyal/kitty · error · ValueError

Invalid color name: {raw!r}

Error message

Invalid color name: {raw!r}

What it means

to_color(raw, validate=True) raises ValueError when Color.parse_color cannot interpret the string as a color (#rrggbb, #rgb, color names, rgb:c/c/c forms).

Source

Thrown at kitty/rgb.py:37

def color_from_int(x: int) -> Color:
    return Color((x >> 16) & 255, (x >> 8) & 255, x & 255)


def color_as_int(x: Color) -> int:
    return int(x)


def color_as_sharp(x: Color) -> str:
    return x.as_sharp


def color_as_sgr(x: Color) -> str:
    return x.as_sgr


def to_color(raw: str, validate: bool = False) -> Color | None:
    if (val := Color.parse_color(raw)) is None and validate:
        raise ValueError(f'Invalid color name: {raw!r}')
    return val

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Use a valid format: named color, #rgb/#rrggbb/#rrggbbaa, or rgb:r/g/b
  2. Validate strings with Color.parse_color before passing when validate=False path is used elsewhere
  3. Fix the typo in the theme/config value

Example fix

# before
to_color('bluu', validate=True)
# after
to_color('#0000ff', validate=True)
Defensive patterns

Strategy: validation

Validate before calling

from kitty.rgb import Color
assert Color.parse_color(raw) is not None, f'bad color: {raw!r}'

Type guard

def is_valid_color(s: str) -> bool: return Color.parse_color(s) is not None

Try / catch

except ValueError: fall back to a default color and warn

Prevention

When it happens

Trigger: Passing strings like 'redd', '#12', 'rgb:1/2' or arbitrary text where a color spec is expected (themes, set-tab-color values, color_control calls).

Common situations: Typos in theme files, dynamically-built color strings without validation, catppuccin/other theme syntax kitty doesn't parse.

Related errors


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