turtle icon indicating copy to clipboard operation
turtle copied to clipboard

Consider human-panic crate

Open stevepentland opened this issue 7 years ago • 6 comments

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.

stevepentland avatar Apr 19 '18 23:04 stevepentland

This is a great idea! I would accept a PR for this from anyone interested. :smile:

Good idea @stevepentland!

sunjay avatar Apr 20 '18 02:04 sunjay

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.

stevepentland avatar Apr 20 '18 11:04 stevepentland

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. :)

sunjay avatar Apr 20 '18 14:04 sunjay

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

sunjay avatar Apr 28 '18 14:04 sunjay

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.

stevepentland avatar Apr 29 '18 19:04 stevepentland

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

sunjay avatar Apr 29 '18 19:04 sunjay