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

json.dumps dies with TypeError: Object of type BusType is not JSON serializable on hid.enumerate() on 1.0.6 #60

Open
RodoMa92 opened this issue May 12, 2024 · 2 comments

Comments

@RodoMa92
Copy link

While debugging the Steam Deck updater program I discovered that #59 causes a regression making it unable to parse the new added field back with the following backtrace:

Traceback (most recent call last):
  File "/var/home/marco/Desktop/jupiter_controller_fw_updater/./d20bootloader.py", line 912, in <module>
    cli()
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/marco/Desktop/jupiter_controller_fw_updater/./d20bootloader.py", line 765, in getdevicesjson
    print(json.dumps(devs))
          ^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type BusType is not JSON serializable

If you need to take a look at the source code of the software, the code is here: https://gitlab.com/evlaV/jupiter-hw-support/-/tree/master/usr/share/jupiter_controller_fw_updater?ref_type=heads

Downgrading back to 1.0.5 makes the program works correctly.

@apmorton
Copy link
Owner

I think this should be reported to https://gitlab.com/evlaV/jupiter-hw-support/-/issues

It's unfortunate 1.0.6 broke that software, but I don't think there is a good way to fix this in pyhidapi without causing even more breakage in other applications which now use BusType.

jupiter-hw-support can either:

  • remove the bus type field before json encoding
  • convert the bus type field to an int before encoding
  • implement a json.JSONEncoder subclass that handles BusType

@antheas
Copy link

antheas commented May 12, 2024

You could always cast bustype as an int before returning it. Unless there is proof it breaks say e.g., match statements

Also, it appears that software is affected more than that print statement. It refuses to work now. We will investigate it.

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

No branches or pull requests

3 participants