{"record":{"id":"8f35db3ca1e480f2","repo":"kovidgoyal/kitty","slug":"name-is-not-a-valid-color","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/tab_bar.py","lineNumber":170,"sourceCode":"\n    def __init__(self, which: str):\n        self.which = which\n\n    def __getattr__(self, name: str) -> str:\n        q = name\n        if q == 'default':\n            ans = '9'\n        elif q == 'tab':\n            col = color_from_int((self.draw_data.tab_bg if self.which == '4' else self.draw_data.tab_fg)(self.tab_data))\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 Formatter:\n    reset = '\\x1b[0m'\n    fg = ColorFormatter('3')\n    bg = ColorFormatter('4')\n    bold = '\\x1b[1m'\n    nobold = '\\x1b[22m'\n    italic = '\\x1b[3m'\n    noitalic = '\\x1b[23m'\n\n\n@run_once\ndef super_sub_maps() -> tuple[dict[int, int], dict[int, int]]:\n    import string\n","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/tab_bar.py#L152-L188","documentation":"Raised by the tab-bar Formatter's __getattr__ when an attribute name is neither a known style key nor parseable as a color. Attribute access like formatter.red or formatter._ff0000 is dynamically converted to SGR escape codes; anything to_color() cannot parse raises AttributeError with this message. Because it's an AttributeError, hasattr() and getattr(default) interact with it normally.","triggerScenarios":"Accessing a Formatter attribute that isn't a color, e.g. formatter.not_a_color, or a malformed hex like formatter._gggggg (after '#' substitution to_color fails).","commonSituations":"Typos in tab-bar.py color names; using an unsupported color syntax in a custom tab bar style function; checking hasattr(formatter, 'bold') style keys that don't exist.","solutions":["Use a valid color name ('red'), 256-color index ('color123'), or _RRGGBB hex form","Use getattr(formatter, 'attr', None) or hasattr to probe optional styles","Check kitty's tab_bar.py for the supported attribute vocabulary"],"exampleFix":"# before\nfg = formatter._zzzzzz\n# after\nfg = formatter._ff0000  # or formatter.red","handlingStrategy":"fallback","validationCode":"from kitty.rgb import to_color\nif to_color(name.lstrip('_').prepend('#') if name.startswith('_') else name) is None:\n    style = formatter.reset","typeGuard":"def is_valid_formatter_color(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    seq = getattr(formatter, token)\nexcept AttributeError:\n    seq = formatter.reset","preventionTips":["Use getattr(formatter, token, formatter.reset) for user-supplied style tokens","Validate custom tab-bar color config at startup with to_color"],"tags":["tab-bar","formatter","color-parsing"],"backgroundTag":"invalid-color-specifier","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}