{"record":{"id":"1ac16c0701b8cd30","repo":"CoplayDev/unity-mcp","slug":"context-must-be-a-list-or-base64-string","errorCode":null,"errorMessage":"{context} must be a list or base64 string","messagePattern":"(.+?) must be a list or base64 string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":173,"sourceCode":"\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\n        trimmed = value.strip()\n        if trimmed.startswith(\"[\") and trimmed.endswith(\"]\"):\n            value = try_parse_json(trimmed, context)\n        else:\n            return f\"base64:{value}\"\n    if isinstance(value, list):\n        expected_count = width * height\n        if len(value) != expected_count:\n            raise ValueError(\n                f\"{context} must have {expected_count} entries, got {len(value)}\")\n        return [_normalize_color(pixel, f\"{context} pixel\") for pixel in value]\n    raise ValueError(f\"{context} must be a list or base64 string\")\n\n\ndef _normalize_set_pixels(value: Any) -> dict[str, Any]:\n    if value is None:\n        raise ValueError(\"set-pixels is required\")\n    if isinstance(value, str):\n        value = try_parse_json(value, \"set-pixels\")\n    if not isinstance(value, dict):\n        raise ValueError(\"set-pixels must be a JSON object\")\n\n    result: dict[str, Any] = dict(value)\n\n    if \"pixels\" in value:\n        width = value.get(\"width\")\n        height = value.get(\"height\")\n        if width is None or height is None:\n            raise ValueError(\n                \"set-pixels requires width and height when pixels are provided\")","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L155-L191","documentation":"Raised by _normalize_pixels (texture.py:173) when the pixels value is not None, not a string (base64 or JSON array), and not a list — i.e. an unsupported type such as an int, float, bool, or dict. The 'context' label is 'set-pixels pixels'. After a non-base64 string is JSON-parsed it may become such a scalar/object, hitting the final fallback.","triggerScenarios":"Passing `--set-pixels '{\"width\":2,\"height\":2,\"pixels\":128}'` (a scalar), or a pixels value of {\"a\":1} (a dict), or a bare number where the pixel array or base64 string was expected.","commonSituations":"Passing a single grayscale int for pixels; a JSON object where an array was intended; mis-typing the pixels field as a scalar.","solutions":["Provide pixels as a JSON array of width*height colors, or as a base64 string (optionally prefixed with 'base64:').","If you intended a solid fill, drop 'pixels' and use 'color' instead.","Ensure the pixels JSON parses to a list or stays a base64 string."],"exampleFix":"# before\nunity-mcp texture modify Assets/Tex.png --set-pixels '{\"x\":0,\"y\":0,\"width\":1,\"height\":1,\"pixels\":128}'\n\n# after\nunity-mcp texture modify Assets/Tex.png --set-pixels '{\"x\":0,\"y\":0,\"width\":1,\"height\":1,\"pixels\":[[128,128,128,255]]}'","handlingStrategy":"type-guard","validationCode":"# Python - accept only list or string for pixels before _normalize_pixels\nif not isinstance(pixels, (list, str)):\n    raise ValueError(f\"{context} must be a list or base64 string\")","typeGuard":"def is_pixels_shape(v) -> bool: return isinstance(v, (list, str))","tryCatchPattern":"try:\n    result = _normalize_set_pixels(set_pixels)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Pass pixels as a JSON array or a base64 string.","Use 'color' for solid fills instead of a scalar in 'pixels'."],"tags":["python","cli","texture","pixels","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"}