{"record":{"id":"a99c7312cb267979","repo":"CoplayDev/unity-mcp","slug":"invalid-hex-color-value","errorCode":null,"errorMessage":"Invalid hex color: {value}","messagePattern":"Invalid hex color: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":101,"sourceCode":"        return False\n\n    all_small = all(0 <= v <= 1.0 for v in numeric_values)\n    if not all_small:\n        return False\n\n    has_fractional = any(0 < v < 1 for v in numeric_values)\n    all_binary = all(v in (0, 1, 0.0, 1.0) for v in numeric_values)\n\n    return has_fractional or all_binary\n\n\ndef _parse_hex_color(value: str) -> list[int]:\n    h = value.lstrip(\"#\")\n    if len(h) == 6:\n        return [int(h[i:i + 2], 16) for i in (0, 2, 4)] + [255]\n    if len(h) == 8:\n        return [int(h[i:i + 2], 16) for i in (0, 2, 4, 6)]\n    raise ValueError(f\"Invalid hex color: {value}\")\n\n\ndef _normalize_color(value: Any, context: str) -> list[int]:\n    if value is None:\n        raise ValueError(f\"{context} is required\")\n\n    if isinstance(value, str):\n        if value.startswith(\"#\"):\n            return _parse_hex_color(value)\n        value = try_parse_json(value, context)\n\n    # Handle dict with r/g/b keys (e.g., {\"r\": 1, \"g\": 0, \"b\": 0} or {\"r\": 1, \"g\": 0, \"b\": 0, \"a\": 1})\n    if isinstance(value, dict):\n        if all(k in value for k in (\"r\", \"g\", \"b\")):\n            try:\n                color = [value[\"r\"], value[\"g\"], value[\"b\"]]\n                if \"a\" in value:\n                    color.append(value[\"a\"])","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L83-L119","documentation":"Raised by _parse_hex_color (texture.py:101) when a hex color string is not exactly 6 or 8 hex digits after stripping the leading '#'. The parser only accepts 6-digit RGB (#RRGGBB, alpha forced to 255) or 8-digit RGBA (#RRGGBBAA). Anything else — wrong length or non-hex characters — is rejected. _parse_hex_color is reached from _normalize_color only when the value starts with '#'.","triggerScenarios":"Passing --color '#FF' (too short), --color '#12345' (5 digits), --color '#GGGGGG' (non-hex chars), or a 7-digit value. Reached via `texture create --color '#...'`, `texture sprite --color`, or any color field in --palette/--set-pixels that is a hex string.","commonSituations":"Typing a 3-digit shorthand (#F00) which isn't supported; forgetting the alpha while typing 7 chars; pasting a color from a tool that emits non-hex or wrong-length strings.","solutions":["Use the supported 6-digit (#RRGGBB) or 8-digit (#RRGGBBAA) hex form.","If you have a 3-digit shorthand, expand it (#F00 -> #FF0000).","Prefer the list form ([255,0,0] or [1,0,0,1]) if you are unsure of the hex length."],"exampleFix":"# before\nunity-mcp texture create Assets/Tex.png --color '#F00'\n\n# after\nunity-mcp texture create Assets/Tex.png --color '#FF0000'","handlingStrategy":"validation","validationCode":"# Python - before calling _parse_hex_color / _normalize_color\nimport re\nif isinstance(value, str) and value.startswith(\"#\"):\n    if not re.fullmatch(r\"#[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?\", value):\n        raise ValueError(f\"Invalid hex color: {value}\")","typeGuard":"import re\ndef is_valid_hex_color(v: str) -> bool:\n    return isinstance(v, str) and v.startswith(\"#\") and re.fullmatch(r\"#[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?\", v) is not None","tryCatchPattern":"try:\n    rgb = _normalize_color(color, \"color\")\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Standardize on #RRGGBB or #RRGGBBAA.","Expand 3-digit shorthands to 6 digits before passing."],"tags":["python","cli","texture","color","validation","value-error"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}