Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tck/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ def wrapper(*args, **kwargs):
except JsonRpcError:
raise
except PrecheckError as e:
logger.error(f"PrecheckError (status: {ResponseCode(e.status).name}, method: {func.__name__})")
logger.error(f"PrecheckError (method: {func.__name__}, status: {ResponseCode(e.status).name})")
raise JsonRpcError.hiero_error({"status": ResponseCode(e.status).name}) from e

except ReceiptStatusError as e:
logger.error(f"ReceiptStatusError (status: {ResponseCode(e.status).name}, method: {func.__name__})")
logger.error(f"ReceiptStatusError (method: {func.__name__}, status: {ResponseCode(e.status).name})")
raise JsonRpcError.hiero_error({"status": ResponseCode(e.status).name}) from e

except MaxAttemptsError as e:
logger.error(f"MaxAttemptsError (method: {func.__name__})")
raise JsonRpcError.hiero_error(message=str(e)) from e
logger.error(f"MaxAttemptsError (method: {func.__name__}, error: {e.message})")
raise JsonRpcError.hiero_error(message=e.message) from e
Comment thread
manishdait marked this conversation as resolved.
Outdated

except Exception as e:
logger.exception("Unhandled error in RPC handler")
logger.error(f"InternalError (method: {func.__name__}) error: {str(e)}")
raise JsonRpcError.internal_error(message="Internal error") from e

return wrapper
14 changes: 12 additions & 2 deletions tck/handlers/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import inspect
import logging
from collections.abc import Callable
from dataclasses import asdict, fields as dc_fields
from typing import Any, get_type_hints
Expand All @@ -13,6 +14,9 @@
from tck.protocol import build_json_rpc_error_response


logger = logging.getLogger(__name__)


# A global _HANDLERS dict to store method name -> handler function mappings
_HANDLERS: dict[str, Callable] = {}

Expand Down Expand Up @@ -43,6 +47,9 @@ def dispatch(method_name: str, params: Any) -> Any:
handler = get_handler(method_name)

if handler is None:
logger.warning(
f"MethodNotFoundError (method: {repr(method_name)}) error: The requested RPC method is not registered."
)
raise JsonRpcError.method_not_found_error(message=f"Method not found: {method_name}")

try:
Expand All @@ -58,6 +65,7 @@ def dispatch(method_name: str, params: Any) -> Any:
param_type = hints.get(param_name, parameters[0].annotation)
params = param_type.parse_json_params(params)
except (TypeError, ValueError) as e:
logger.error(f"InvalidParamsError (method: {repr(method_name)}) error: {str(e)}")
raise JsonRpcError.invalid_params_error(data=str(e)) from e

result = handler(params)
Expand All @@ -67,7 +75,8 @@ def dispatch(method_name: str, params: Any) -> Any:
except JsonRpcError:
Comment thread
manishdait marked this conversation as resolved.
Outdated
raise
except Exception as e:
raise JsonRpcError.internal_error(data=str(e)) from e
logger.error(f"InternalError (method: {repr(method_name)}) error: {str(e)}")
Comment thread
manishdait marked this conversation as resolved.
raise JsonRpcError.internal_error(message="An unexpected system error occurred.") from e


def safe_dispatch(method_name: str, params: Any, request_id: str | int | None) -> Any | dict[str, Any]:
Expand All @@ -77,7 +86,8 @@ def safe_dispatch(method_name: str, params: Any, request_id: str | int | None) -
except JsonRpcError as e:
return build_json_rpc_error_response(e, request_id)
except Exception as e:
error = JsonRpcError.internal_error(data=str(e))
logger.error(f"InternalError (method: {repr(method_name)}) error: {str(e)}")
error = JsonRpcError.internal_error(message="An unexpected system error occurred.")
return build_json_rpc_error_response(error, request_id)
Comment thread
exploreriii marked this conversation as resolved.


Expand Down
Loading