Improve error message when sketch file is executed without ever being saved
Running a module mode sketch file without saving causes the setup()/settings() separation feature to fail. The error message only mentions other issues that cause this feature to fail. It would be great if we could find a way of improving this.
The things that I can think of are:
- Improve the error message mentioning that another cause of the problem is the file might not yet have been saved
- Detect the unsaved state of the file on the IDE and provide a different message. On Thonny
print(__file__)throws aNameErrorif the file was never saved.
Note: On Thonny IDE, this is not an issue using the plugin that enables imported mode, because then, if the sketch was never saved, the IDE prompts the user to save the file when you hit the run button!
@villares , thanks for spotting this issue and opportunity to improve py5.
It might be possible for py5 to pre-emptively detect that the setup() function's __file__ is <string> and save it to a temporary file. I'll consider this as a possibility when I work on fixing this.
It might be possible for py5 to pre-emptively detect that the
setup()function's__file__is<string>and save it to a temporary file. I'll consider this as a possibility when I work on fixing this.
@villares , that won't work without side effects. Instead, I will improve the error message:
I made some other changes so there will be no ugly exception. Just a clear message. Would you like to wordsmith a better message than what I have there?