A lua error in lua code within setup() can cause knock-on surprising issues in draw()

If you have a bug in your lua code which is run during setup(), that will cause a lua error which is reported to the print window. All good and proper.

Also, the subsequent code in setup() after your error will not be run. Also reasonable.

Your code under draw() will still be run. This produces more errors, because some of your setup code was not run. This situation was a bit perplexing to me. Not for long but it certainly doesn’t adhere to the principle of least surprise. I was thinking Oh yes, there is an error on line 20 in my setup. But how come there are also errors on line 550 in my drawing code? What is up with that suddenly? … Goes off to read his drawing code.

(An aside. I notice that a lua error raised in any code under draw() will cause a [Pause], and you can [Play] your code even though it has raised errors. This is quite a nice feature, and not what I would have expected but at least the message “Pausing playback” gives you all the information. There is no such message with an error raised during setup() lua code, because play back is not paused. Also reasonable).

BTW I’m not suggesting that your code under draw() is not run when there is an error in setup(). I’m thinking there is a more elegant solution.

Thanks for reporting this @Martin — could you log it on the issue tracker? https://bitbucket.org/TwoLivesLeft/codea/issues

This sounds like a bug with the way setup() is run.

Actually I noticed you are still using the previous version of Codea. We changed the say setup() is called in version 1.3. Please check to see if this issue is fixed in 1.3 before reporting it on the tracker.

I was completely meaning to say “Codea 1.2.6” at the end of my post, then clean forgot. Apologies.

This bug is addressed in 1.3. Execution of code ceases after an error in setup() and in draw(). You can unpause and continue execution if you choose. It feels reasonable.