{"record":{"id":"30b3040f1b9727ca","repo":"CoplayDev/unity-mcp","slug":"set-pixels-width-and-height-must-be-positive","errorCode":null,"errorMessage":"set-pixels width and height must be positive","messagePattern":"set-pixels width and height must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":195,"sourceCode":"    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\"])\n    if \"y\" in value:\n        result[\"y\"] = int(value[\"y\"])\n\n    if \"width\" in value and \"pixels\" not in value:\n        result[\"width\"] = int(value[\"width\"])","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L177-L213","documentation":"Thrown by _normalize_set_pixels() when pixels are provided and width/height are present but one or both are <= 0 after int() coercion. Texture dimensions must be positive integers; zero or negative sizes are rejected before pixel normalization runs.","triggerScenarios":"Passing width or height as 0, a negative number, or a numeric string that parses to a non-positive int, e.g. `--set-pixels '{\"pixels\":[...],\"width\":0,\"height\":4}'`. Also when a non-numeric value triggers an earlier int() failure (that surfaces as a different ValueError).","commonSituations":"Dimensions computed from another source produce zero (e.g. an empty image's width), or a typo/sign error yields negatives. Common in generated commands where a size variable defaulted to 0.","solutions":["Set width and height to positive integers that multiply to the pixel count.","If dimensions are computed, add an assertion `assert width > 0 and height > 0` before building the payload.","Cross-check the pixel array length equals width*height."],"exampleFix":"// before\n--set-pixels '{\"pixels\":[\"#FF0000\"],\"width\":0,\"height\":1}'\n// after\n--set-pixels '{\"pixels\":[\"#FF0000\"],\"width\":1,\"height\":1}'","handlingStrategy":"validation","validationCode":"w, h = int(sp[\"width\"]), int(sp[\"height\"])\nif w <= 0 or h <= 0:\n    raise ValueError(\"set-pixels width and height must be positive\")","typeGuard":"def dims_positive(v: dict) -> bool:\n    return all(int(v[k]) > 0 for k in (\"width\", \"height\") if k in v)","tryCatchPattern":"try:\n    payload = _normalize_set_pixels(sp)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Assert dimensions are positive when computed from other sources.","Keep width*height equal to the pixel count."],"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"}