From 7d1a37587347d344403caddf9754d03070f6a51f Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 8 Mar 2024 19:48:11 -0500 Subject: [PATCH] chore: add detail to encoding TypeError (#127) --- dank_mids/requests.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dank_mids/requests.py b/dank_mids/requests.py index d3920274..6ef5cb7d 100644 --- a/dank_mids/requests.py +++ b/dank_mids/requests.py @@ -627,7 +627,16 @@ def __repr__(self) -> str: def data(self) -> bytes: if not self.calls: raise EmptyBatch(f"batch {self.uid} is empty and should not be processed.") - return msgspec.json.encode([call.request for call in self.calls]) + try: + return msgspec.json.encode([call.request for call in self.calls]) + except TypeError: + # If we can't encode one of the calls, lets figure out which one and pass some useful info downstream + for call in self.calls: + try: + msgspec.json.encode(call.request) + except TypeError as e: + raise TypeError(e, call.request) from None + raise @property def is_multicalls_only(self) -> bool: