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
python: catch-all hardcoded error can hide real error in cast of input to numpy #541
Comments
Thanks for the very detailed report. I had a look at the pybind11 doc and came up with the following:
I then created a truncated png file that raises your aforementioned error when trying explicitly loading it via
That looks only marginally better than what the current HEAD revision is providing. I don't see how I could influence what happens behind the If you have ideas, please let me know. Otherwise I'll push the above change and consider it at least an improvement. |
I saw various chatter about numpy and that python-pillow/Pillow#6588 (but I didn't really dig in: my impression was numpy >= 1.23 was "fine".) Only think I can think of is a different code path based on To elaborate: I don't know the design/layout well enough but is it possible to have a thin layer of actual python code? I mean if instance(x, PIL.Image):
# force load now to get an error messages at this point, Issue #541
x.load()
pybind11.magic.call._read_barcodes(x, ...) |
I think this code tries to ensure the image can be cast to a particular numpy format
But the actual error message of
catch(...)
might be useful and is hidden.For example: suppose I have an image that is broken, maybe b/c some idiot only read half the bytes:
Now if I read this in, surely Pillow will choke somewhere:
But this error is confusing b/c we do have a PIL Image!
Explanation
To understand, what is happening, compare to:
TL-DR
The PIL Image is going to give a very reasonable error on lazy load, but ZXingcpp will catch that error and replace it with hardcoded best-guess error.
A possible fix
Echo the actual error message before speculating about possible unsupported types. I don't really speak enough C++ but the pseudocode change I'd like is something like this:
References
A real-life example where this made it harder to debug is https://gitlab.com/plom/plom/-/issues/2597
The text was updated successfully, but these errors were encountered: