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

OverflowError error message description should be improved #339

Closed
kerrick-lyft opened this issue Oct 2, 2019 · 3 comments
Closed

OverflowError error message description should be improved #339

kerrick-lyft opened this issue Oct 2, 2019 · 3 comments

Comments

@kerrick-lyft
Copy link

kerrick-lyft commented Oct 2, 2019

Right now, ujson gives this error when you try to encode certain types (e.g. numpy.bool_) that cannot be encoded:

OverflowError: Maximum recursion level reached

For example, you can get this error by running this code:

import numpy
import ujson
print(ujson.dumps(numpy.bool_(True)))

This error does not indicate what actually went wrong, which is that numpy.bool_ objects cannot be encoded.

As a basic fix for this problem, I'd suggest changing the error message to:

OverflowError: Maximum recursion level reached (maybe you tried encoding a type of object that isn't supported?)
@kerrick-lyft
Copy link
Author

kerrick-lyft commented Oct 2, 2019

I opened a PR to fix this issue: #340

@hugovk
Copy link
Member

hugovk commented Mar 13, 2020

Hello, thank you very much for the issue and PR.

Since UltraJSON 2.0 was released with 53f85b1, this is no longer valid:

Removed generic serialization of objects/iterables

The behavior of ujson has always been to try to serialize all objects in
any way possible. This has been quite a deviation from other json
libraries, including Pythons standard json module, and the source of a
lot of confusion and bugs. Removing this quirk moves ultrajson closer to
the expected behavior.

Instead of trying to coerce serialization ultrajson will now throw a
TypeError: "repr(obj) is not JSON serializable" exception.

Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(.startup.py)
(imported collections, datetime, itertools, math, os, pprint, re, sys, time)
>>> import numpy
>>> import ujson
>>> ujson.dumps(numpy.bool_(True))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: � is not JSON serializable
>>>

The "�" bit is another issue: #258.

So let's close this. Thanks again for contributing!

@hugovk hugovk closed this as completed Mar 13, 2020
@kerrick-lyft
Copy link
Author

Awesome, thanks for continuing to improve ujson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants