python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.32k stars 2.23k forks source link

How could I let warning be error? #8539

Closed CoinCheung closed 2 weeks ago

CoinCheung commented 2 weeks ago

I have plenty of images, so I process them with multi-processing. However, when I run the script, I got the errors like

/opt/miniconda3/envs/py310/lib/python3.10/site-packages/PIL/TiffImagePlugin.py:900: UserWarning: Truncated File Read
  warnings.warn(str(msg))

I cannot know which image brings this warning, since it is merely warning. Would you tell me how to make this warning an error so that I can catch it?

By the way, I have already checked the start bytes and end bytes of the image files, there should not be truncated images...

radarhere commented 2 weeks ago

You can add

import warnings
warnings.filterwarnings("error")

before you run your code to treat warnings as errors.

CoinCheung commented 2 weeks ago

Thanks, it works for me.