{"record":{"id":"c50ce8a7c1b12e8b","repo":"CoplayDev/unity-mcp","slug":"set-pixels-must-be-a-json-object","errorCode":null,"errorMessage":"set-pixels must be a JSON object","messagePattern":"set-pixels must be a JSON object","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":182,"sourceCode":"            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\")\n        width = int(width)\n        height = int(height)\n        if width <= 0 or height <= 0:\n            raise ValueError(\"set-pixels width and height must be positive\")\n        result[\"width\"] = width\n        result[\"height\"] = height\n        result[\"pixels\"] = _normalize_pixels(\n            value[\"pixels\"], width, height, \"set-pixels pixels\")\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L164-L200","documentation":"Thrown by _normalize_set_pixels() when, after an optional JSON-string parse, the value is not a Python dict. Because try_parse_json already converts JSON strings to objects, this fires when the parsed JSON is an array, number, string, or boolean, or when the caller passes a non-dict Python value (e.g. a list) directly. The command requires a JSON object because it reads keys like pixels, color, width, height.","triggerScenarios":"Passing set-pixels as a JSON array or scalar string such as `--set-pixels '[1,2,3]'` or `--set-pixels '42'`, or calling _normalize_set_pixels with a list/number. Passing valid JSON that is not an object (e.g. a bare quoted string).","commonSituations":"A developer pastes a pixel array directly as set-pixels instead of wrapping it in an object (`{\"pixels\":[...]}`), or confuses the set-pixels object with the raw pixels list. Also happens when the JSON string is quoted so it parses to a scalar.","solutions":["Wrap the payload in a JSON object: `--set-pixels '{\"pixels\":[...],\"width\":2,\"height\":2}'`.","If using color fill, use `--set-pixels '{\"color\":\"#FF0000\",\"width\":2,\"height\":2}'`.","Validate the JSON with `python -c \"import json,sys; print(type(json.loads(sys.argv[1])))\" '<value>'` to confirm it is a dict before running."],"exampleFix":"// before\n--set-pixels '[\"#FF0000\",\"#00FF00\"]'\n// after\n--set-pixels '{\"color\":\"#FF0000\",\"width\":2,\"height\":2}'","handlingStrategy":"type-guard","validationCode":"import json\nif isinstance(value, str):\n    value = json.loads(value)  # will raise JSONDecodeError, distinct from this error\nif not isinstance(value, dict):\n    raise ValueError(\"set-pixels must be a JSON object\")","typeGuard":"def is_set_pixels_obj(v) -> bool:\n    if isinstance(v, str):\n        try:\n            v = json.loads(v)\n        except json.JSONDecodeError:\n            return False\n    return isinstance(v, dict)","tryCatchPattern":"try:\n    payload = _normalize_set_pixels(raw)\nexcept ValueError as e:\n    # report and exit\n    ...","preventionTips":["Wrap arrays/scalars in an object before passing as set-pixels.","Validate parsed JSON type is dict before normalizing."],"tags":["cli","validation","texture","input-validation","json"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}