{"record":{"id":"55c67ccb3f4ecba3","repo":"Textualize/textual","slug":"invalid-color-value-color","errorCode":null,"errorMessage":"Invalid color value {color}","messagePattern":"Invalid color value (.+?)","errorType":"validation","errorClass":"StyleValueError","httpStatus":null,"severity":"error","filePath":"src/textual/css/_style_properties.py","lineNumber":1027,"sourceCode":"                        alpha = percentage_string_to_float(token)\n                    except ValueError:\n                        raise StyleValueError(f\"invalid percentage value '{token}'\")\n                    continue\n                try:\n                    parsed_color = Color.parse(token)\n                except ColorParseError as error:\n                    raise StyleValueError(\n                        f\"Invalid color value '{token}'\",\n                        help_text=color_property_help_text(\n                            self.name, context=\"inline\", error=error, value=token\n                        ),\n                    )\n            parsed_color = parsed_color.multiply_alpha(alpha)\n\n            if obj.set_rule(self.name, parsed_color):\n                obj.refresh(children=True)\n        else:\n            raise StyleValueError(f\"Invalid color value {color}\")\n\n\nclass ScrollbarColorProperty(ColorProperty):\n    \"\"\"A descriptor to set scrollbar color(s).\"\"\"\n\n    def __set__(self, obj: StylesBase, color: Color | str | None) -> None:\n        super().__set__(obj, color)\n\n        if obj.node is None:\n            return\n\n        from textual.widget import Widget\n\n        if isinstance(obj.node, Widget):\n            widget = obj.node\n\n            if widget.show_horizontal_scrollbar:\n                widget.horizontal_scrollbar.refresh()","sourceCodeStart":1009,"sourceCodeEnd":1045,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/css/_style_properties.py#L1009-L1045","documentation":"The else-branch of ColorProperty.__set__ fires when the assigned color is neither None, a Color instance, nor a str — i.e. an entirely wrong Python type such as int, tuple, or list. Unlike the token-level parse error (which handles bad strings), this rejects the value before any parsing because its type is unparseable.","triggerScenarios":"`styles.color = (255, 0, 0)` (RGB tuple), `styles.color = 0xFF0000` (int), `styles.color = [\"red\"]` — anything that is not None, Color, or str.","commonSituations":"Porting code from GUI frameworks that accept tuples (Tkinter, pygame) or passing config-driven values without normalization to strings/Color objects.","solutions":["Convert tuples to `Color(r, g, b)` or a color string before assignment","Add isinstance validation when style values come from external data"],"exampleFix":"# before\nstyles.color = (255, 0, 0)\n# after\nfrom rich.color import Color\nstyles.color = Color(255, 0, 0)","handlingStrategy":"type-guard","validationCode":"from rich.color import Color\nif color is None or isinstance(color, (str, Color)):\n    styles.color = color","typeGuard":"def is_color_value(v) -> bool:\n    return v is None or isinstance(v, (str, Color))","tryCatchPattern":null,"preventionTips":["Convert RGB tuples to Color(r,g,b) at the config boundary"],"tags":["textual","css","color","type-error"],"backgroundTag":"type-validation-failed","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}