{"record":{"id":"addc6607d4aac355","repo":"kovidgoyal/kitty","slug":"name-is-not-a-valid-color-addc66","errorCode":null,"errorMessage":"{name} is not a valid color","messagePattern":"(.+?) is not a valid color","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"kitty/window_title_bar.py","lineNumber":67,"sourceCode":"        elif q == 'window':\n            opts = get_options()\n            if self.is_active:\n                fg_color = _resolve_color(opts.window_title_bar_active_foreground, opts.active_tab_foreground)\n                bg_color = _resolve_color(opts.window_title_bar_active_background, opts.active_tab_background)\n                col = color_from_int(color_as_int(fg_color if self.which == '3' else bg_color))\n            else:\n                fg_color = _resolve_color(opts.window_title_bar_inactive_foreground, opts.inactive_tab_foreground)\n                bg_color = _resolve_color(opts.window_title_bar_inactive_background, opts.inactive_tab_background)\n                col = color_from_int(color_as_int(fg_color if self.which == '3' else bg_color))\n            ans = f'8{color_as_sgr(col)}'\n        elif q.startswith('color'):\n            ans = f'8:5:{int(q[5:])}'\n        else:\n            if name.startswith('_'):\n                q = f'#{name[1:]}'\n            c = to_color(q)\n            if c is None:\n                raise AttributeError(f'{name} is not a valid color')\n            ans = f'8{color_as_sgr(c)}'\n        return f'\\x1b[{self.which}{ans}m'\n\n\nclass WindowTitleFormatter:\n    reset = '\\x1b[0m'\n    fg = WindowTitleColorFormatter('3')\n    bg = WindowTitleColorFormatter('4')\n    bold = '\\x1b[1m'\n    nobold = '\\x1b[22m'\n    italic = '\\x1b[3m'\n    noitalic = '\\x1b[23m'\n\n\nclass WindowTitleData(NamedTuple):\n    title: str\n    is_active: bool\n    window_id: int","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/window_title_bar.py#L49-L85","documentation":"Raised by __getattr__ in kitty's window title bar color formatter when a color-like attribute name passed to the SGR color formatter cannot be parsed by to_color(). The class synthesizes ANSI escape sequences from attribute names like 'red', '#ff00ff' (via '_ff00ff'), or 'indexed:N', and any name that isn't a recognized color spec raises AttributeError. It is an AttributeError rather than ValueError because it occurs during dynamic attribute access.","triggerScenarios":"Accessing a color attribute on the title-bar formatter object with an invalid name, e.g. formatter.notacolor, formatter._zzzzzz (malformed hex), or an indexed color spec that doesn't parse; any name where to_color(q) returns None.","commonSituations":"Typos in theme/config color names, using CSS color names kitty doesn't support, malformed hex like '_ff00f' (5 digits), or passing a variable that is None/empty so the attribute name becomes garbage.","solutions":["Correct the color name to one kitty's to_color() accepts: standard color names, #RRGGBB (accessed as _RRGGBB), or indexed:N / 8:5:N specs","Validate color strings with kitty.rgb.to_color() before using them as attribute names","If the attribute isn't meant to be a color, rename it so it doesn't collide with __getattr__-based color lookup"],"exampleFix":"// before\nsgr = formatter.my_colr  # typo -> AttributeError: my_colr is not a valid color\n\n# after\nsgr = formatter._ff0000  # explicit hex red, or a name to_color() accepts","handlingStrategy":"validation","validationCode":"from kitty.rgb import to_color\n\ndef valid_color(name: str) -> bool:\n    q = f'#{name[1:]}' if name.startswith('_') else name\n    return to_color(q) is not None","typeGuard":"def is_valid_color_name(name: str) -> bool:\n    from kitty.rgb import to_color\n    q = f'#{name[1:]}' if name.startswith('_') else name\n    return to_color(q) is not None","tryCatchPattern":"try:\n    sgr = getattr(formatter, name)\nexcept AttributeError as e:\n    if 'is not a valid color' in str(e):\n        sgr = ''  # skip or use default color\n    else:\n        raise","preventionTips":["Validate color strings with kitty.rgb.to_color() before turning them into attribute lookups","Keep user-configurable color names in a curated allowlist","Lint theme configs for color names at load time"],"tags":["kitty","colors","attributeerror","terminal"],"backgroundTag":"invalid-color-value","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}