{"record":{"id":"6ff2f6976a79cb74","repo":"CoplayDev/unity-mcp","slug":"set-pixels-requires-width-and-height-when-pixels-a","errorCode":null,"errorMessage":"set-pixels requires width and height when pixels are provided","messagePattern":"set-pixels requires width and height when pixels are provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":190,"sourceCode":"        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\n    if \"color\" in value:\n        result[\"color\"] = _normalize_color(value[\"color\"], \"set-pixels color\")\n\n    if \"pixels\" not in value and \"color\" not in value:\n        raise ValueError(\"set-pixels requires 'color' or 'pixels'\")\n\n    if \"x\" in value:\n        result[\"x\"] = int(value[\"x\"])","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L172-L208","documentation":"Thrown by _normalize_set_pixels() when the set-pixels object contains a 'pixels' key but is missing 'width' and/or 'height'. Pixel data is meaningless without dimensions, so the normalizer refuses to proceed and requires both fields alongside the pixel array.","triggerScenarios":"Passing `--set-pixels '{\"pixels\":[...]}'` without width/height, or providing only one of width/height. Reproducible whenever the pixels array is present but the dimension keys are absent or named differently.","commonSituations":"A developer assumes default dimensions exist (they don't — only create() has width/height defaults, not set-pixels), or uses camelCase/alternate key names that aren't recognized.","solutions":["Add both width and height: `--set-pixels '{\"pixels\":[...],\"width\":2,\"height\":2}'`.","Ensure width*height equals the pixel count (a separate ValueError guards count mismatch).","For a uniform fill, drop the pixels array and use color instead: `--set-pixels '{\"color\":\"#FF0000\",\"width\":2,\"height\":2}'`."],"exampleFix":"// before\n--set-pixels '{\"pixels\":[\"#FF0000\",\"#00FF00\"]}'\n// after\n--set-pixels '{\"pixels\":[\"#FF0000\",\"#00FF00\"],\"width\":2,\"height\":1}'","handlingStrategy":"validation","validationCode":"if \"pixels\" in sp and (\"width\" not in sp or \"height\" not in sp):\n    raise ValueError(\"set-pixels requires width and height when pixels are provided\")","typeGuard":"def has_pixels_with_dims(v: dict) -> bool:\n    return \"pixels\" not in v or (\"width\" in v and \"height\" in v)","tryCatchPattern":"try:\n    payload = _normalize_set_pixels(sp)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Always pair a pixels array with explicit width and height.","Compute dims from len(pixels) when filling a single row."],"tags":["cli","validation","texture","input-validation"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}