Skip to content
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

Do not catch a ValueError only to raise another #5090

Merged
merged 1 commit into from Dec 29, 2020

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Dec 12, 2020

Helps #4926

The unaddressed part of that issue is that there is a chain of three ValueErrors raised by the following code.

>>> from PIL import Image
>>> img = Image.new('F', (200,100), 1.0)
>>> img.putalpha(Image.new('L', (200,100), 255))
Traceback (most recent call last):
  File "PIL/Image.py", line 1620, in putalpha
    self.im.setmode(mode)
ValueError: image has wrong mode

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "PIL/Image.py", line 1623, in putalpha
    im = self.im.convert(mode)
ValueError: conversion from F to LA not supported

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/Image.py", line 1630, in putalpha
    raise ValueError("illegal image mode") from e
ValueError: illegal image mode

This PR reduces it to two.

>>> from PIL import Image
>>> img = Image.new('F', (200,100), 1.0)
>>> img.putalpha(Image.new('L', (200,100), 255))
Traceback (most recent call last):
  File "PIL/Image.py", line 1620, in putalpha
ValueError: image has wrong mode

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/Image.py", line 1623, in putalpha
ValueError: conversion from F to LA not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants