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
More informative FileNotFoundError #2694
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I like the idea behind this PR. It should be really helpful for many newbies when they get FileNotFound errors in their code, and this info will help them debug better
I also updated this so it absolute paths will do the normal python thing and say what file isn't found. I can't believe it didn't do that before!
instead of just
Also, just to be clear, I'm just doing these changes on Python 3, because I don't want to expend the effort testing them on Python 2, which is getting dropped soonTM anyway. (It's in an existing #ifdef) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great usability improvement. Thanks! 🎉
LGTM
So... this could probably be slightly inaccurate on some platforms where SDL_RWOps loads assets differently, but at least on Android (the only relevant one because PyGame officially aims to support it) the APK asset loading via JNI is done in addition to regular fopen() in the current directory, so it works out, and you can still put your assets into your P4A code directory. Just something to keep in mind in the future... |
Thank you for the reviews everyone. I think this can be delayed merging, until #2695 is merged, and that should be delayed merging until 2.0.2 is out. |
I an surprised. I would think this is such a minor patch for such a useful feature, and it saves everybody so many grey hairs... I would want this in sooner rather than later |
It's because right now it only works on mixer.Sound, and the patch that makes it work on significantly more things, #2695, is not a minor change. |
Also a feature telling to use os.path.join with images would be useful |
Yeah, some sort of feature for case-insensitivty/path handling would be good. Probably most code should use pathlib now rather than os.path.join though. I think this can probably be done best at the linter/code editor level though... because I'm not sure how to do it inside pygame. |
This PR adds a more informative FileNotFoundError to pygame's RWops system.
Take this, for example:
Normally, if there's a problem, pygame will say:
Which is accurate, but not super helpful, especially for newbies. And I see newbies struggle with the concept of working directories a lot.
This PR uses the os module to produce this error message instead:
This could obviously still be misinterpreted, but the term "working directory" will hopefully point people in a good direction with Google searches.
And this information is omitted for absolute paths, because for those it doesn't matter what your working directory is. And if the
os
module is unavailable for some reason, it will just fall back to the old error message.However, there's a problem. Most of pygame's loading functions make really complex use of the pg_RWops API, rather than using the more high level functions. So, right now, this FileNotFound will only be emitted by Sound objects failing to load. I will broaden this a lot in a companion PR, kept separate for ease of review.