{"record":{"id":"9f8ee9129ae6cf83","repo":"CoplayDev/unity-mcp","slug":"context-is-required","errorCode":null,"errorMessage":"{context} is required","messagePattern":"(.+?) is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":106,"sourceCode":"\n    has_fractional = any(0 < v < 1 for v in numeric_values)\n    all_binary = all(v in (0, 1, 0.0, 1.0) for v in numeric_values)\n\n    return has_fractional or all_binary\n\n\ndef _parse_hex_color(value: str) -> list[int]:\n    h = value.lstrip(\"#\")\n    if len(h) == 6:\n        return [int(h[i:i + 2], 16) for i in (0, 2, 4)] + [255]\n    if len(h) == 8:\n        return [int(h[i:i + 2], 16) for i in (0, 2, 4, 6)]\n    raise ValueError(f\"Invalid hex color: {value}\")\n\n\ndef _normalize_color(value: Any, context: str) -> list[int]:\n    if value is None:\n        raise ValueError(f\"{context} is required\")\n\n    if isinstance(value, str):\n        if value.startswith(\"#\"):\n            return _parse_hex_color(value)\n        value = try_parse_json(value, context)\n\n    # Handle dict with r/g/b keys (e.g., {\"r\": 1, \"g\": 0, \"b\": 0} or {\"r\": 1, \"g\": 0, \"b\": 0, \"a\": 1})\n    if isinstance(value, dict):\n        if all(k in value for k in (\"r\", \"g\", \"b\")):\n            try:\n                color = [value[\"r\"], value[\"g\"], value[\"b\"]]\n                if \"a\" in value:\n                    color.append(value[\"a\"])\n                else:\n                    color.append(1.0 if _is_normalized_color(color) else 255)\n                if _is_normalized_color(color):\n                    return [int(round(float(c) * 255)) for c in color]\n                return [int(c) for c in color]","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L88-L124","documentation":"Raised by _normalize_color (texture.py:106) when the color value is None. The 'context' is a label identifying which field is missing (e.g. 'color', 'set-pixels color', 'palette item', 'set-pixels pixels pixel'). _normalize_color is called from the create/sprite --color options, from _normalize_palette per item, from _normalize_pixels per pixel, and from _normalize_set_pixels for the color key. The CLI wraps these in try/except ValueError -> print_error -> exit(1).","triggerScenarios":"Passing null/None for a color where one is required: a palette entry that is null (`--palette '[null]'`), a set-pixels color of null, or a pixels array containing null entries. Note the top-level --color flag itself defaults to white if omitted, so the top-level create/sprite path rarely hits this; it is more common in palette/pixel/set-pixels arrays.","commonSituations":"A JSON palette or pixels array with a null element; a set-pixels payload missing the color value but flagged as having one; programmatic construction that leaves a color entry as None.","solutions":["Provide a concrete color (hex string, [r,g,b] list, or {r,g,b} dict) for every required color entry.","Filter nulls out of palette/pixel arrays before passing them.","Validate the JSON structure of --palette/--set-pixels before invoking the CLI."],"exampleFix":"# before\nunity-mcp texture create Assets/Tex.png --pattern checkerboard --palette '[null, \"#FF0000\"]'\n\n# after\nunity-mcp texture create Assets/Tex.png --pattern checkerboard --palette '[\"#FFFFFF\", \"#FF0000\"]'","handlingStrategy":"validation","validationCode":"# Python - ensure required colors are not None before _normalize_color\nif value is None:\n    raise ValueError(f\"{context} is required\")","typeGuard":"def has_color_value(v) -> bool: return v is not None","tryCatchPattern":"try:\n    color = _normalize_color(value, context)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Filter None out of palette/pixel arrays.","Provide explicit colors for every required field."],"tags":["python","cli","texture","color","validation","value-error"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}