Skip to content

Commit f5985be

Browse files
committed
ENH: Give more helpful error message on serialization fail
1 parent bf20d34 commit f5985be

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/runrms/api/proxy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ def _send_request(self, request: Request) -> Response:
154154
response.traceback,
155155
)
156156
return response
157+
except TypeError as e:
158+
raise TypeError(
159+
"Unable to serialize request to rmsapi. This can happen for "
160+
"several reasons:\n"
161+
"1. You're using an attribute like 'some.attr' directly. You must "
162+
"instead use 'some.attr.get()' to use the actual value.\n"
163+
"2. You're passing an object where some attribute is being used "
164+
"in a way similar to 1. You must called '.get()' on it first.\n"
165+
f"Details: Request: {request}, Error: {e}"
166+
) from e
157167
except zmq.Again as e:
158168
logger.error(f"Request timed out after {self._rcv_timeout_ms}ms")
159169
raise TimeoutError(f"Request timed out: {e}") from e

tests/test_api/test_proxy.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,11 @@ def test_get_on_root_raises(proxy_with_mocks: RmsApiProxy) -> None:
531531
"""get() on root proxy raises."""
532532
with pytest.raises(RuntimeError, match="Cannot get value of root proxy"):
533533
proxy_with_mocks.get()
534+
535+
536+
def test_no_get_on_dict_key_raises(proxy_with_mocks: RmsApiProxy) -> None:
537+
"""Helpful serialization error is raised when using an RmsApiProxy as an arg."""
538+
some = {}
539+
540+
with pytest.raises(TypeError, match="Unable to serialize request to rmsapi"):
541+
some[proxy_with_mocks.some_attr] = "foo"

0 commit comments

Comments
 (0)