Skip to content

Commit 5548bac

Browse files
committed
Improve JSON-RPC error messages and logging
- Pre-initialize method = "" instead of locals().get() in the internal-error log path - Reject JSON arrays with a clear "Batch requests not supported" message rather than the generic "Request must be object"
1 parent 2afc221 commit 5548bac

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

quarkchain/cluster/jsonrpc_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ def wrapper(f):
9292
async def dispatch(self, request_json: Dict[str, Any], context=None) -> Optional[Dict[str, Any]]:
9393
req_id = None
9494
is_notification = False
95+
method = ""
9596

9697
try:
98+
if isinstance(request_json, list):
99+
raise InvalidRequest("Batch requests not supported")
97100
if not isinstance(request_json, dict):
98101
raise InvalidRequest("Request must be object")
99102

@@ -147,7 +150,7 @@ async def dispatch(self, request_json: Dict[str, Any], context=None) -> Optional
147150
"id": req_id,
148151
}
149152
except Exception:
150-
logger.exception("Internal JSON-RPC error for method %s", locals().get("method", "<unknown>"))
153+
logger.exception("Internal JSON-RPC error for method %s", method)
151154
if is_notification:
152155
return None
153156
return {

0 commit comments

Comments
 (0)