Comfy-Org/ComfyUI · error · ValueError

Color must be in format #RRGGBB or #RRGGBBAA

Error message

Color must be in format #RRGGBB or #RRGGBBAA

What it means

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.

Source

Thrown at comfy_extras/nodes_color.py:28

            node_id="ColorToRGBInt",
            display_name="Color Picker",
            category="utilities",
            description="Return a color RGB integer value and hexadecimal representation.",
            inputs=[
                io.Color.Input("color"),
            ],
            outputs=[
                io.Int.Output(display_name="rgb_int"),
                io.Color.Output(display_name="hex"),
                io.Float.Output(display_name="alpha"),
            ],
        )

    @classmethod
    def execute(cls, color: str) -> io.NodeOutput:
        # expect format #RRGGBB or #RRGGBBAA
        if len(color) not in (7, 9) or color[0] != "#":
            raise ValueError("Color must be in format #RRGGBB or #RRGGBBAA")
        try:
            int(color[1:], 16)
        except ValueError:
            raise ValueError("Color must be in format #RRGGBB or #RRGGBBAA") from None

        alpha = 1.0
        if len(color) == 9:
            alpha = int(color[7:9], 16) / 255.0
            color = color[:7]

        r, g, b = hex_to_rgb(color)

        rgb_int = r * 256 * 256 + g * 256 + b
        return io.NodeOutput(rgb_int, color, alpha)


class ColorExtension(ComfyExtension):
    @override

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Normalize the value to '#RRGGBB' or '#RRGGBBAA' before the node: strip whitespace and prepend '#' if missing.
  2. Expand 3-digit shorthand (#abc -> #aabbcc) upstream.
  3. Convert named colors to hex before wiring in.
  4. If the value comes from another node, insert a small string-format step that enforces the 7/9-character form.

Example fix

# before
color = "ff0000"
# after
color = "#ff0000"
Defensive patterns

Strategy: validation

Validate before calling

import re
HEX_RE = re.compile(r"^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$")
def valid_color(c: str) -> bool:
    return isinstance(c, str) and bool(HEX_RE.match(c))

Type guard

def is_hex_color(c) -> bool:
    return isinstance(c, str) and HEX_RE.match(c) is not None

Try / catch

try:
    out = node.execute(color)
except ValueError:
    color = "#" + color.lstrip("#")
    out = node.execute(color)

Prevention

When it happens

Trigger: 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 '#'.

Common situations: 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.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/d6d5aab672c557c7. Report an issue: GitHub.