{"record":{"id":"435ee7173abcfcf0","repo":"CoplayDev/unity-mcp","slug":"unexpected-error-e","errorCode":null,"errorMessage":"Unexpected error: {e}","messagePattern":"Unexpected error: (.+?)","errorType":"exception","errorClass":"UnityConnectionError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/utils/connection.py","lineNumber":126,"sourceCode":"            response.raise_for_status()\n            return response.json()\n    except httpx.ConnectError as e:\n        raise UnityConnectionError(\n            f\"Cannot connect to Unity MCP server at {cfg.host}:{cfg.port}. \"\n            f\"Make sure the server is running and Unity is connected.\\n\"\n            f\"Error: {e}\"\n        )\n    except httpx.TimeoutException:\n        raise UnityConnectionError(\n            f\"Connection to Unity timed out after {timeout or cfg.timeout}s. \"\n            f\"Unity may be busy or unresponsive.\"\n        )\n    except httpx.HTTPStatusError as e:\n        raise UnityConnectionError(\n            f\"HTTP error from server: {e.response.status_code} - {e.response.text}\"\n        )\n    except Exception as e:\n        raise UnityConnectionError(f\"Unexpected error: {e}\")\n\n\ndef run_command(\n    command_type: str,\n    params: Dict[str, Any],\n    config: Optional[CLIConfig] = None,\n    timeout: Optional[int] = None,\n) -> Dict[str, Any]:\n    \"\"\"Synchronous wrapper for send_command.\n\n    Args:\n        command_type: The command type\n        params: Command parameters\n        config: Optional CLI configuration\n        timeout: Optional timeout override\n\n    Returns:\n        Response dict from Unity","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/utils/connection.py#L108-L144","documentation":"Thrown by send_command() as a catch-all when an exception is neither ConnectError, TimeoutException, nor HTTPStatusError. It wraps the original exception's message. Because the more specific handlers run first, this indicates an unusual failure such as an invalid URL, a JSON decode error on a non-JSON body, or an SSL/protocol problem.","triggerScenarios":"The server returns a non-JSON body causing response.json() to raise; a malformed host value yields an InvalidURL; or an SSL/TLS handshake error occurs against an https endpoint. Any unexpected httpx or stdlib exception falls here.","commonSituations":"A proxy returns HTML instead of JSON, the host string contains invalid characters, or a TLS mismatch when the endpoint is HTTPS. Often a symptom of misconfigured networking rather than the Unity layer.","solutions":["Read the wrapped exception text to identify the underlying type (e.g. JSONDecodeError, InvalidURL).","If the body is not JSON, check for a proxy or gateway intercepting the request.","Validate UNITY_MCP_HOST is a plain hostname/IP without scheme or path.","Reproduce with verbose httpx logging to capture the original exception."],"exampleFix":"# before\nexport UNITY_MCP_HOST=http://localhost  # invalid: includes scheme\n# after\nexport UNITY_MCP_HOST=localhost","handlingStrategy":"try-catch","validationCode":"import re\nhost = os.environ.get(\"UNITY_MCP_HOST\", \"127.0.0.1\")\nif not re.fullmatch(r\"[A-Za-z0-9.\\-]+\", host):\n    raise ValueError(f\"Invalid UNITY_MCP_HOST value: {host!r}\")","typeGuard":null,"tryCatchPattern":"try:\n    return await send_command(cmd, params)\nexcept UnityConnectionError as e:\n    # Unexpected: log the wrapped exception for diagnosis\n    log.exception(str(e))\n    raise","preventionTips":["Keep UNITY_MCP_HOST a plain hostname or IP.","Disable intercepting proxies for localhost."],"tags":["cli","network","http","unexpected"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}