py5generator icon indicating copy to clipboard operation
py5generator copied to clipboard

Improve error message when sketch file is executed without ever being saved

Open villares opened this issue 1 year ago • 1 comments

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.

image

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 a NameError if 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 avatar Apr 08 '24 01:04 villares

@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.

hx2A avatar Apr 10 '24 02:04 hx2A

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:

image

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?

hx2A avatar Jun 14 '24 03:06 hx2A