Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Change the exception type when parsing bad data

Open jleclanche opened this issue 9 years ago • 7 comments

Right now PIL/Pillow recommends raising SyntaxError when dealing with bad data. Example in PaletteFile:

            if len(s) > 100:
                raise SyntaxError("bad palette file")

It'd be a lot nicer raising a custom exception. Abusing SyntaxError is nasty.

jleclanche avatar Jan 05 '16 05:01 jleclanche

Hi. Thanks for contributing with this suggestion. My only input here is that there are many SyntaxError exceptions thrown throughout the image plugins, so if done properly, this is actually a bigger change than simply PaletteFile.

radarhere avatar Jan 22 '16 01:01 radarhere

I agree, yes.

jleclanche avatar Jan 22 '16 01:01 jleclanche

Each encoder should catch and homogenize potential errors thrown to this more canonical form.

meawoppl avatar Jan 29 '16 01:01 meawoppl

@jleclanche You want to take a whack at this one?

aclark4life avatar Jan 05 '17 23:01 aclark4life

@aclark4life yeah sure, but this is quite the backwards incompatible change. fine with that?

jleclanche avatar Jan 05 '17 23:01 jleclanche

If only we had looked at a list of things to do for a breaking change release

wiredfool avatar Jan 06 '17 23:01 wiredfool

#7425 and #7489 would also like custom exceptions instead of OSErrors.

radarhere avatar Sep 30 '23 02:09 radarhere