{"record":{"id":"d8f96ba0cda96400","repo":"CoplayDev/unity-mcp","slug":"context-must-be-a-list-or-hex-string","errorCode":null,"errorMessage":"{context} must be a list or hex string","messagePattern":"(.+?) must be a list or hex string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":143,"sourceCode":"            except (TypeError, ValueError):\n                raise ValueError(f\"{context} dict values must be numeric, got {value}\")\n        raise ValueError(f\"{context} dict must have 'r', 'g', 'b' keys, got {list(value.keys())}\")\n\n    if isinstance(value, (list, tuple)):\n        if len(value) == 3:\n            value = list(value) + [1.0 if _is_normalized_color(value) else 255]\n        if len(value) == 4:\n            try:\n                if _is_normalized_color(value):\n                    return [int(round(float(c) * 255)) for c in value]\n                return [int(c) for c in value]\n            except (TypeError, ValueError):\n                raise ValueError(\n                    f\"{context} values must be numeric, got {value}\")\n        raise ValueError(\n            f\"{context} must have 3 or 4 components, got {len(value)}\")\n\n    raise ValueError(f\"{context} must be a list or hex string\")\n\n\ndef _normalize_palette(value: Any, context: str) -> list[list[int]]:\n    if value is None:\n        return []\n    if isinstance(value, str):\n        value = try_parse_json(value, context)\n    if not isinstance(value, list):\n        raise ValueError(f\"{context} must be a list of colors\")\n    return [_normalize_color(color, f\"{context} item\") for color in value]\n\n\ndef _normalize_pixels(value: Any, width: int, height: int, context: str) -> list[list[int]] | str:\n    if value is None:\n        raise ValueError(f\"{context} is required\")\n    if isinstance(value, str):\n        if value.startswith(\"base64:\"):\n            return value","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L125-L161","documentation":"Raised by _normalize_color (texture.py:143) when the value is not None, not a (hex) string, not a dict, and not a list/tuple — i.e. an unsupported scalar type such as an int, float, or bool. The 'context' label names the field. After a non-# string is JSON-parsed it may become one of these unsupported types, hitting the final fallback.","triggerScenarios":"Passing --color '128' (a bare integer), --color '1.0', or a JSON string that parses to a scalar. Applies to any color argument (color, palette item, pixel, set-pixels color).","commonSituations":"Passing a grayscale int expecting it to expand; a JSON string that evaluates to a number instead of an array/object; a boolean where a color was expected.","solutions":["Pass a color as a hex string (#RRGGBB), a [r,g,b] list, or an {r,g,b} dict.","If you meant grayscale, expand it to a 3- or 4-element array (e.g. [128,128,128]).","Ensure JSON color arguments parse to an array or object, not a scalar."],"exampleFix":"# before\nunity-mcp texture create Assets/Tex.png --color '128'\n\n# after\nunity-mcp texture create Assets/Tex.png --color '[128,128,128]'","handlingStrategy":"type-guard","validationCode":"# Python - accept only supported color shapes before _normalize_color\nok = value is None or isinstance(value, str) or isinstance(value, dict) or isinstance(value, (list, tuple))\nif not ok:\n    raise ValueError(f\"{context} must be a list or hex string\")","typeGuard":"def is_color_shape(v) -> bool: return v is None or isinstance(v,(str,dict,list,tuple))","tryCatchPattern":"try:\n    color = _normalize_color(value, context)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Never pass a bare scalar (int/float/bool) as a color.","Expand grayscale ints to [v,v,v] first."],"tags":["python","cli","texture","color","validation","value-error","type-error"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}