{"record":{"id":"d6d5aab672c557c7","repo":"Comfy-Org/ComfyUI","slug":"color-must-be-in-format-rrggbb-or-rrggbbaa","errorCode":null,"errorMessage":"Color must be in format #RRGGBB or #RRGGBBAA","messagePattern":"Color must be in format #RRGGBB or #RRGGBBAA","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_color.py","lineNumber":28,"sourceCode":"            node_id=\"ColorToRGBInt\",\n            display_name=\"Color Picker\",\n            category=\"utilities\",\n            description=\"Return a color RGB integer value and hexadecimal representation.\",\n            inputs=[\n                io.Color.Input(\"color\"),\n            ],\n            outputs=[\n                io.Int.Output(display_name=\"rgb_int\"),\n                io.Color.Output(display_name=\"hex\"),\n                io.Float.Output(display_name=\"alpha\"),\n            ],\n        )\n\n    @classmethod\n    def execute(cls, color: str) -> io.NodeOutput:\n        # expect format #RRGGBB or #RRGGBBAA\n        if len(color) not in (7, 9) or color[0] != \"#\":\n            raise ValueError(\"Color must be in format #RRGGBB or #RRGGBBAA\")\n        try:\n            int(color[1:], 16)\n        except ValueError:\n            raise ValueError(\"Color must be in format #RRGGBB or #RRGGBBAA\") from None\n\n        alpha = 1.0\n        if len(color) == 9:\n            alpha = int(color[7:9], 16) / 255.0\n            color = color[:7]\n\n        r, g, b = hex_to_rgb(color)\n\n        rgb_int = r * 256 * 256 + g * 256 + b\n        return io.NodeOutput(rgb_int, color, alpha)\n\n\nclass ColorExtension(ComfyExtension):\n    @override","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_color.py#L10-L46","documentation":"Thrown by the color parsing node's `execute` when the input string does not start with '#' or is not exactly 7 (#RRGGBB) or 9 (#RRGGBBAA) characters long. The node only accepts the leading-hash hex form; named colors ('red'), 3-digit shorthand ('#f00'), and hashless hex ('ff0000') are all rejected at this length/prefix check before any hex parsing happens.","triggerScenarios":"Calling the node with 'red', 'FF0000' (no '#'), '#F00' (shorthand), '#FF00000' (8 hex digits interpreted wrongly), an empty string, or any value whose length is not 7 or 9. A common trigger is a widget that strips or never included the leading '#'.","commonSituations":"Copying colors from CSS where 3-digit shorthand or rgb() notation is used; frontend color pickers that emit hex without '#'; trailing whitespace or newline accidentally included in the string.","solutions":["Normalize the value to '#RRGGBB' or '#RRGGBBAA' before the node: strip whitespace and prepend '#' if missing.","Expand 3-digit shorthand (#abc -> #aabbcc) upstream.","Convert named colors to hex before wiring in.","If the value comes from another node, insert a small string-format step that enforces the 7/9-character form."],"exampleFix":"# before\ncolor = \"ff0000\"\n# after\ncolor = \"#ff0000\"","handlingStrategy":"validation","validationCode":"import re\nHEX_RE = re.compile(r\"^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$\")\ndef valid_color(c: str) -> bool:\n    return isinstance(c, str) and bool(HEX_RE.match(c))","typeGuard":"def is_hex_color(c) -> bool:\n    return isinstance(c, str) and HEX_RE.match(c) is not None","tryCatchPattern":"try:\n    out = node.execute(color)\nexcept ValueError:\n    color = \"#\" + color.lstrip(\"#\")\n    out = node.execute(color)","preventionTips":["Normalize user color input with a regex before passing it on.","Expand CSS shorthand and named colors to 6-digit hex in your adapter code.","Strip whitespace around widget strings."],"tags":["validation","color","string-format","comfyui"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}