ADD error catching - #109
Conversation
|
@Nycto This one is a bit rough still, see my comments. I thought I'd first make a PR to see if you'd agree to this idea before polishing it. Note there is also a question for you in there regarding a possibility to have a single proc for both typed and untyped usage. |
| with: | ||
| nim-version: ${{ matrix.nim-version }} | ||
| - run: nimble test | ||
| - run: nimble test --warning[BareExcept]:off |
There was a problem hiding this comment.
This seems not to be picked up: https://github.com/samdze/playdate-nim/actions/runs/14674842933/job/41189152091?pr=109
| assert(result == 0) | ||
|
|
||
| test "runCatching untyped with exception": | ||
| if runnable: |
There was a problem hiding this comment.
Do we expect this to be run on the headless test? the whole sparsemap suite and System APi suite seems to be missing in the logs https://github.com/samdze/playdate-nim/actions/runs/14674842933/job/41189152102?pr=109
| except Exception as e: | ||
| logException(e, fatal, messagePrefix) | ||
| when compiles(result): # result is only defined if body is a proc that has a return type | ||
| result # default value for inferred return type |
There was a problem hiding this comment.
default(body) does not work here.
Also, return must not be used in a template
| ## if fatal is true, the game will pause | ||
| try: | ||
| body() | ||
| except Exception as e: |
There was a problem hiding this comment.
while running tests, this line spams BareExcept warnings
|
Hello Samuele! My name is Roman, I'm a Golang software engineer, and in my spare time I'm developing this project, I think it could be interesing for you, because you are author of Nim bindings for Playdate, which is great, thank you for this work !!! Finally, Playdate meets the Golang programming language! If you’re not familiar with Golang: it’s a modern, high-performance language developed by Google powering tools like Docker, Kubernetes, and many others. And now, it’s coming to the Playdate platform! Thanks for attention, and sorry in advance for disturbing you. In case if you are interested: Main regularly updated PdGo devlog (Playdate Development Forum): https://devforum.play.date/t/golang-support-for-playdate-compiler-sdk-bindings-tools-and-examples/24919 Project repository: https://github.com/playdate-go/pdgo Project internals #1: https://github.com/playdate-go/pdgo#internals Project internals #2: https://github.com/playdate-go/pdgo?tab=readme-ov-file#why-not-go-but-tinygo |
|
Hi @AmorBielyi Thanks for sharing. For clarity though, this project is focused specifically on Nim, and the Go tooling you’re referring to is unrelated at both the language and implementation level. I may be missing something, but I don’t see any opportunity for overlap. But I do wish you good luck with your project; It’s always good to see the community grow. In the future, though, please open a new issue instead of co-opting an unrelated pull request. |

What is it
A proc that will execute a provided lambda and catch any errors. The exception is printed to the console.
Optionally, the error is marked as fatal, causing the simulator to be paused and the error message to be printed in red.
This is manly intended to add default error catching to the main update loop, but it can also be used in game code if desired. Sample usage is added
Why
Challenges
handlercall in theinitSdkmacro too but that is executed very early in the boot sequence and I couldn't figure that outOut of scope
I plan a follow-up PR where the error is printed to the screen (device only, since simulator has the Console view). This provides a similar crash experience to the lua sdk and allows players to share a photo of the stacktrace with the dev, as is common practice for lua games.