dlenski / python-zxing

python wrapper for the ZXing barcode library
GNU Lesser General Public License v3.0
121 stars 36 forks source link

Insufficient handling of missing result in BarCode.__repr__ #36

Closed stefan6419846 closed 3 months ago

stefan6419846 commented 3 months ago

When there is no result for a file, id est we have the standard output

file:///home/stefan/temp/image-001.png: No barcode found

then displaying the result will fail as BarCode.__repr__ does not like it:

Traceback (most recent call last):
  File "/home/stefan/temp/run.py", line 57, in <module>
    print(reader.decode(path))
  File "/home/stefan/temp/venv/lib/python3.9/site-packages/zxing/__init__.py", line 238, in __repr__
    self.__class__.__name__, self.raw, self.parsed, self.raw_bits.hex(),
AttributeError: 'NoneType' object has no attribute 'hex'
dlenski commented 3 months ago

88ca242c88688fa4e46cf8f1108915a1c821ae9b should fix this, thanks. However, I wasn't even able to reproduce this using the "normal" entry point of BarCode.parse on the latest version.

What version are/were you using? zxing --version should show it, or python3 -m zxing.__main__ --version from the build directory.

stefan6419846 commented 3 months ago

I was using the latest master branch due to the broken PyPI builds.

dlenski commented 3 months ago

Thanks. I overlooked this case, added a test to ensure it's handled right in f24a995.