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
pygame.errror exceptions are too generic #1535
Comments
This is a good enhancement. I don't have time to do this myself anytime soon, but PRs are welcome. The first step would be to make some unit tests. I've added a task list. |
Can I work on it? |
I would like to work on this if it's still available |
Of course, any help would be appreciated |
I would be interested to work on this as well. |
Here are a couple of error codes that IMG_GetError returns. >>> import pygame
pygame 2.0.0.dev7 (SDL 2.0.12, python 3.7.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> pygame.image.load("asdf.png")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pygame.error: Couldn't open asdf.png
>>> pygame.image.load("/etc/passwd")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pygame.error: Unsupported image format |
Closing thanks to the PR from @dotmars that was merged. Thanks! |
src_c/
to raise FileNotFoundError when file isn't there.When loading an image with a file that doesn't exist, you get a
pygame.error
exception with a human-readable string description of the error. This is an anti-pattern. It would be better to allow the built-in exceptionIOError
orFileNotFoundError
to bubble up.Let's say I want to handle an error where an image isn't found on disk. I currently have to check
os.path.isfile(path)
. If the file does exist, and I usepygame.image.load(path)
, that's two file stats, which is not as efficient as simply catching the exception that is normally thrown when a file doesn't exist.Either the original exception should be allowed to raise, or pygame should define its own version of
FileNotFoundError
. There may be other instances of this anti-pattern throughout pygame, but so far this is all I've come across.The text was updated successfully, but these errors were encountered: