{"record":{"id":"d2c01e35b699f39b","repo":"can1357/oh-my-pi","slug":"response-get-code-if-str-else-null","errorCode":"{response.get(\"code\") if str else null}","errorMessage":"{response.get(\"error\", \"\")}","messagePattern":"\\{response\\.get\\(\"error\", \"\"\\)\\}","errorType":"exception","errorClass":"RpcCommandError","httpStatus":null,"severity":"error","filePath":"python/omp-rpc/src/omp_rpc/client.py","lineNumber":1408,"sourceCode":"            with self._state_lock:\n                self._pending.pop(request_id, None)\n            raise\n\n        try:\n            response = response_queue.get(timeout=self._request_timeout)\n        except queue.Empty as exc:\n            with self._state_lock:\n                self._pending.pop(request_id, None)\n            raise RpcTimeoutError(\n                f\"Timed out waiting for response to {command_type}. Stderr: {self.stderr}\"\n            ) from exc\n\n        if isinstance(response, BaseException):\n            raise response\n\n        if not bool(response.get(\"success\", False)):\n            raw_code = response.get(\"code\")\n            raise RpcCommandError(\n                command=str(response.get(\"command\", command_type)),\n                error=str(response.get(\"error\", \"\")),\n                code=raw_code if isinstance(raw_code, str) else None,\n            )\n\n        data = response.get(\"data\")\n        if data is None:\n            return {}\n        return _clone_json_object(data)\n\n    def _send_notification(self, payload: JsonObject) -> None:\n        process = self._require_process()\n        self._write_json(process, payload)\n\n    def _normalize_host_tool_result(self, result: object) -> JsonObject:\n        if isinstance(result, str):\n            return {\"content\": [{\"type\": \"text\", \"text\": result}]}\n        if isinstance(result, Mapping):","sourceCodeStart":1390,"sourceCodeEnd":1426,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/python/omp-rpc/src/omp_rpc/client.py#L1390-L1426","documentation":"RpcCommandError raised when the server responded success=false for a command. It carries the failing command name, the server-provided error string (response['error'], empty string if absent), and an optional string code from response['code'] (None if the code isn't a string).","triggerScenarios":"Any _request command the server rejects: invalid arguments, unknown command, session errors, server-side validation failures. The error text comes verbatim from the server payload.","commonSituations":"Calling commands with wrong payload shapes after a protocol version change; referencing a missing session/model; server-side tool or permission denials.","solutions":["Read exc.error (and exc.code) for the server's specific reason and fix the request payload accordingly","Verify the command name and arguments against the server's protocol version","Catch RpcCommandError around _request-style calls and branch on code where the server defines codes","Update client and server packages together if a protocol mismatch causes systematic rejections"],"exampleFix":"try:\n    client.set_model(\"gpt-5\")\nexcept RpcCommandError as exc:\n    if exc.code == \"model-not-found\":\n        client.set_model(\"gpt-5-mini\")\n    else:\n        raise","handlingStrategy":"try-catch","validationCode":"# validate payload keys/types against the protocol before sending\ndef validate_command(name: str, payload: dict) -> None:\n    required = COMMAND_SCHEMAS[name]\n    missing = required.keys() - payload.keys()\n    if missing:\n        raise ValueError(f\"missing args: {missing}\")","typeGuard":null,"tryCatchPattern":"try:\n    client.run_command(\"set_model\", model=model_id)\nexcept RpcCommandError as exc:\n    match exc.code:\n        case \"model-not-found\": pick_fallback_model()\n        case _: raise","preventionTips":["Log exc.command, exc.error, exc.code on every RpcCommandError","Keep client and server protocol versions in lockstep","Validate command payloads against the documented schema before sending"],"tags":["rpc","server-error","command","protocol"],"backgroundTag":"rpc-command-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}