UnicodeDecodeError while importing C extension

Have anyone ever stepped upon something like this? A user from a repository which I help maintaining reported this crashing while running it on an arm64 build, on Apple Silicon. I couldn’t reproduce the error and haven’t found anything about this on the Internet.

Please, note that harmony is a pure Python package while charmony is a C extension for this package.

Traceback (most recent call last):
  File "/Users/adrian/Library/Python/3.11/bin/harmony", line 5, in <module>
    from harmony.harmony.main import app
  File "/Users/adrian/Library/Python/3.11/lib/python/site-packages/harmony/harmony/main.py", line 7, in <module>
    from harmony.color_sorting.commands import sort
  File "/Users/adrian/Library/Python/3.11/lib/python/site-packages/harmony/color_sorting/commands.py", line 6, in <module>
    from harmony import core, core_services
  File "/Users/adrian/Library/Python/3.11/lib/python/site-packages/harmony/core/__init__.py", line 1, in <module>
    from charmony import CIELAB, HSL, RGB, Color
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Are you sure it’s UTF-8? If the data starts 0XFF 0xFE then maybe it’s UTF-16LE.

But what exactly is it trying to decode? The error happens while importing the C extension, which in MacOS is compiled in a Mach-O file. No Mach-O file starts with 0xff.

There are bugs in the code of charmony. Some of the structs for members and getset, e.g. RGB__members and RGB__getset, lack sentinels at the end. That’s probably the cause.

1 Like

It was it! Thank you! I was going crazy about it haha