Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add debugging details to msgspec.ValidationError #223

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Changes from all 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
4 changes: 2 additions & 2 deletions dank_mids/_exceptions.py
Original file line number Diff line number Diff line change
@@ -108,10 +108,10 @@ def try_again_in(self) -> float:
decimal_string = self.response.error.data['try_again_in']
if "ms" in decimal_string:
ms = float(decimal_string[:-2])
logger.info("rate limited by chainstack, retrying in %sms", ms)
logger.warning("rate limited by chainstack, retrying in %sms", ms)
return ms / 1000
elif "µs" in decimal_string:
µs = float(decimal_string[:-2])
logger.info("rate limited by chainstack, retrying in %sµs", µs)
logger.warning("rate limited by chainstack, retrying in %sµs", µs)
return µs / 1000000
raise NotImplementedError(f"must define a handler for decimal_string {decimal_string}")
6 changes: 5 additions & 1 deletion dank_mids/types.py
Original file line number Diff line number Diff line change
@@ -294,7 +294,11 @@ def decode(self, partial: Literal[True]) -> PartialResponse:...
def decode(self, partial: Literal[False] = False) -> Response:...
def decode(self, partial: bool = False) -> Union[Response, PartialResponse]:
"""Decode the wrapped `msgspec.Raw` object into a `Response` or a `PartialResponse`."""
return msgspec.json.decode(self._raw, type=PartialResponse if partial else Response)
try:
return msgspec.json.decode(self._raw, type=PartialResponse if partial else Response)
except msgspec.ValidationError as e:
e.args = (*e.args, f"decoded: {msgspec.json.decode(self._raw)}")
raise

JSONRPCBatchRequest = List[Request]
# NOTE: A PartialResponse result implies a failure response from the rpc.