def validate_custom_color_format(color_value, color_format, alone_when_single):
    """Raise error if value or its type isn't valid.

    This is different from the validation provided by
    the get_custom_color_format_info function, cause it
    evaluates an specific subset of the possible valid color
    representations.
    """
    ### get the format name and length of the color value
    format_name, length = get_custom_color_format_info(color_value)

    ### if the color format requested is rgb integers but
    ### the color value isn't or doesn't contain rgb
    ### values, raise a TypeError

    if color_format == "rgb_tuple" and "rgb" not in format_name:

        raise TypeError(
            "since the 'color_format' argument"
            " was set to 'rgb_tuple', individual"
            " colors must be represented by a tuple"
            " of integers representing rgb(a) values"
            " with 0 <= integer <= 255"
        )

    ### if the color format requested is hex string but
    ### the color value isn't or doesn't contain hex
    ### strings, raise a TypeError

    elif color_format == "hex_string" and "hex" not in format_name:

        raise TypeError(
            "since the 'color_format' was set to"
            " 'hex_string', individual colors must be"
            " represented by a string formated as an "
            " hex color string; for instance, '#ffffff'"
            " or '#ffffffff'"
        )

    ### if the color value represents a single color
    ### and is requested to use the color itself as
    ### the color value (the alone_when_single is True),
    ### but instead it is represented by a tuple of color
    ### values (thus containing the 'multiple' substring in
    ### its format_name), raise a ValueError

    if length == 1 and alone_when_single and "multiple" in format_name:

        raise ValueError(
            "when color value represents a single"
            " color, it must be the color itself,"
            " not a tuple of colors of length 1"
        )

    ### if the color value represents a single color but
    ### otherwise it is requested to not use the color
    ### itself as the color value (the alone_when_single
    ### is False) and it is not represented by a tuple
    ### of color values but rather the color itself (thus
    ### containing the 'single' substring in its
    ### format_name), raise a ValueError

    elif length == 1 and not alone_when_single and "single" in format_name:

        raise ValueError(
            "when the color value represents a single"
            " color, it must still be a tuple of"
            " colors with length 1, not the color"
            " itself"
        )

    ### if we reach this point in the function, it means
    ### no error was raised; we return the format name and
    ### length of the color value to indicate the validation
    ### was sucessful (since we can return any "truthful"
    ### value, we decide on this info, so it can optionally
    ### be reused when needed after validating a color value)
    return format_name, length
Raise error if value or its type isn't valid.

    This is different from the validation provided by
    the get_custom_color_format_info function, cause it
    evaluates an specific subset of the possible valid color
    representations.
    
nodezator/ourstdlibs/color/custom.py