{"record":{"id":"5d2b9dd6859ef35e","repo":"CoplayDev/unity-mcp","slug":"context-must-have-expected-count-entries-got","errorCode":null,"errorMessage":"{context} must have {expected_count} entries, got {len(value)}","messagePattern":"(.+?) must have (.+?) entries, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":170,"sourceCode":"        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\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\")","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L152-L188","documentation":"Raised by _normalize_pixels (texture.py:170) when the pixels list length does not equal width*height. Each entry is one pixel; the count must match the declared dimensions exactly. Context is 'set-pixels pixels'. The expected_count is computed as width*height from the set-pixels payload (which already validated width/height > 0).","triggerScenarios":"Passing a pixels array whose length != width*height, e.g. `--set-pixels '{\"width\":2,\"height\":2,\"pixels\":[[255,0,0,255]]}'` (1 pixel for a 2x2=4 target), or a 4-pixel array for a 3x3=9 target.","commonSituations":"Mismatch between declared width/height and the actual pixel count; flattening a 2D grid incorrectly; off-by-one in row/column counts; copying a pixels array from a different-sized texture.","solutions":["Make the pixels array length exactly width*height (row-major).","Recompute the array from your source image at the declared width/height.","Double-check width and height in the payload match the data you supplied."],"exampleFix":"# before\nunity-mcp texture modify Assets/Tex.png --set-pixels '{\"x\":0,\"y\":0,\"width\":2,\"height\":2,\"pixels\":[[255,0,0,255]]}'\n\n# after\nunity-mcp texture modify Assets/Tex.png --set-pixels '{\"x\":0,\"y\":0,\"width\":2,\"height\":2,\"pixels\":[[255,0,0,255],[0,255,0,255],[0,0,255,255],[255,255,0,255]]}'","handlingStrategy":"validation","validationCode":"# Python - check pixel count before _normalize_pixels\nexpected = width * height\nif isinstance(pixels, list) and len(pixels) != expected:\n    raise ValueError(f\"pixels must have {expected} entries, got {len(pixels)}\")","typeGuard":"def pixel_count_matches(pixels, width, height) -> bool: return isinstance(pixels, list) and len(pixels) == width * height","tryCatchPattern":"try:\n    result = _normalize_set_pixels(set_pixels)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Lay out pixels row-major and length width*height.","Regenerate the array whenever you change width or height."],"tags":["python","cli","texture","pixels","validation","value-error"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}