roboflow/supervision · error · ValueError

Invalid length of color hash

Error message

Invalid length of color hash

What it means

Error "Invalid length of color hash" thrown in roboflow/supervision.

Source

Thrown at src/supervision/draw/color.py:60

    "#D2F53C",
    "#FABEBE",
    "#008080",
    "#E6BEFF",
    "#AA6E28",
    "#FFFAC8",
    "#800000",
    "#AAFFC3",
]

ROBOFLOW_COLOR_PALETTE = ["C28DFC", "A351FB", "8315F9", "6706CE", "5905B3", "4D049A"]


def _validate_color_hex(color_hex: str) -> None:
    color_hex = color_hex.lstrip("#")
    if not all(c in "0123456789abcdefABCDEF" for c in color_hex):
        raise ValueError("Invalid characters in color hash")
    if len(color_hex) not in (3, 4, 6, 8):
        raise ValueError("Invalid length of color hash")


@dataclass
class Color:
    """
    Represents a color in RGBA format.

    This class provides methods to work with colors, including creating colors from hex
    codes, converting colors to hex strings, RGB tuples, BGR tuples, RGBA tuples,
    and BGRA tuples.

    Attributes:
        r: Red channel value (0-255).
        g: Green channel value (0-255).
        b: Blue channel value (0-255).
        a: Alpha channel value (0-255). Default is 255 (fully opaque).

    Example:

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Use a hex color string of the correct length: #RGB, #RGBA, #RRGGBB, or #RRGGBBAA.
  2. Strip any trailing characters and verify the string after '#' has 3, 4, 6, or 8 characters.

When it happens

Trigger: Thrown at src/supervision/draw/color.py:60 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/acc00d0f6cd93bfc. Report an issue: GitHub.