turtle
turtle copied to clipboard
Consider human-panic crate
As panics are an integral part of Turtle, we may wish to consider making them more friendly for users. I recently came across the human-panic and there may be some merit if it is included in Turtle.
This is a great idea! I would accept a PR for this from anyone interested. :smile:
Good idea @stevepentland!
Sure, I can test it out and put it into a PR unless you really want to save it for a first-timer. If not, then feel free to assign the issue to me and I'll get on it.
No need to save it if you're willing to do it. I just labeled it that way because I believe it can be done by anyone. :)
Since this crate works by replacing std::panic::catch_unwind, it may actually be too intrusive to add to turtle because the application using this crate might not want or expect the different behavior that human panic adds.
I do really like the panic messages though, so maybe we can instead replace our calls to panic!, unreachable!, etc. with some custom macros (e.g. turtle_panic!, turtle_unreachable!, etc.) that output nice messages similar to the human panic crate.
We should disable these macros in tests so it doesn't make them annoying to write. That can be done with #[cfg(not(test))]. In tests, we can just do the default behavior.
Note that we wouldn't want this for every single panic. Just the ones where the message starts with bug:.
That would be a good idea for the core lib yes. My main point of inclusion for human-panic was all of the example applications. That way, if there is a problem in the future (such as the recent macOS bug), a user will have nice output and a log file to submit.
That's a great idea! In that case I think we should really look into catch_unwind and see if we can use that to produce a nice error message to get people to report problems. We could use it in the main function for the renderer process since that only panics if something on our end went wrong (e.g. the recent MacOS bug).