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

Better Traceback for JSON Serialization Failures #930

Closed
rmorshea opened this issue Feb 15, 2023 Discussed in #927 · 1 comment · Fixed by #1008
Closed

Better Traceback for JSON Serialization Failures #930

rmorshea opened this issue Feb 15, 2023 Discussed in #927 · 1 comment · Fixed by #1008
Labels
priority-2-moderate Should be resolved on a reasonable timeline. release-patch Warrents a patch release
Milestone

Comments

@rmorshea
Copy link
Collaborator

Discussed in #927

Originally posted by numpde February 13, 2023
The following grim traceback was caused by writing button(disabled=mutation) instead of ...=mutation.loading, and it's representative of a fairly common set. It would be great to have a pointer to near the origin of the error.

Exception inside application: Object of type Mutation is not JSON serializable
...
Traceback (most recent call last):
  File "REPO/venv-3.11/lib/python3.11/site-packages/django_idom/websocket/consumer.py", line 48, in disconnect
    await self._idom_dispatcher_future
  File "REPO/venv-3.11/lib/python3.11/site-packages/django_idom/websocket/consumer.py", line 124, in _run_dispatch_loop
    await serve_layout(
  File "REPO/venv-3.11/lib/python3.11/site-packages/idom/core/serve.py", line 41, in serve_layout
    async with create_task_group() as task_group:
  File "REPO/venv-3.11/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
  File "REPO/venv-3.11/lib/python3.11/site-packages/idom/core/serve.py", line 52, in _single_outgoing_loop
    await send(await layout.render())
  File "REPO/venv-3.11/lib/python3.11/site-packages/channels/generic/websocket.py", line 271, in send_json
    await super().send(text_data=await self.encode_json(content), close=close)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "REPO/venv-3.11/lib/python3.11/site-packages/channels/generic/websocket.py", line 279, in encode_json
    return json.dumps(content)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Mutation is not JSON serializable
@rmorshea
Copy link
Collaborator Author

As per this comment we should report a more proximal error when in debug mode (for the sake of performance)? If we do this, then it probably makes sense to also catch serialization errors and suggest running in debug mode to get a more useful traceback.

@rmorshea rmorshea added priority-2-moderate Should be resolved on a reasonable timeline. release-patch Warrents a patch release labels Feb 15, 2023
@rmorshea rmorshea added this to the 1.0.1 milestone Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-2-moderate Should be resolved on a reasonable timeline. release-patch Warrents a patch release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant