It’s a nice summary about error handling in Rust, but doesn’t present anything new for anyone who has been writing Rust for a while.<p>The title “more than you’ve ever wanted to know about errors in Rust” had me expecting to learn something new.<p>Still a nice intro though, and could for example form part of the documentation for shuttle in the future, to help people who are new to Rust get into using shuttle.
> However in Rust, panics cannot be recovered from, there is no way to incept a panic in the current thread.<p>You definitely can: <a href="https://doc.rust-lang.org/std/panic/fn.catch_unwind.html" rel="nofollow noreferrer">https://doc.rust-lang.org/std/panic/fn.catch_unwind.html</a>
I was very happy to see a recap of all the basics. Sometimes, with new crates coming and going, I worry/imagine I may be falling behind on the latest "rustic" ways to handle certain things like this.
If you're writing library code and you are new to rust, just stick with `thiserror` and nest your error types (ie: have lower-level errors wrapped up in higher-level errors using #[from]). It's barely more effort than using the Any* error types and the benefits of having concrete errors greatly outweigh the tiny bit of extra effort.
Remember,<p><pre><code> std::result::Result<T, E>
</code></pre>
does not restrict<p><pre><code> E: std::error:Err
</code></pre>
Whereas the article doesn't say that this is the case, but it mentioned it in a way that confused me: <a href="https://www.shuttle.rs/blog/2022/06/30/error-handling#:~:text=The%20Error%20trait%20is%20defined%20in%20the%20standard%20library.%20It%20basically%20represents%20the%20expectations%20of%20error%20values%20%2D%20values%20of%20type%20E%20in%20Result%3CT%2CE%3E">https://www.shuttle.rs/blog/2022/06/30/error-handling#:~:tex...</a>.
I find the concept of unrecoverable panics extremely weird. Crashing your entire program just because something unexpected happened? Erlang would lime a word with you :)
Anyhow and Eyre seem cool, but completely losing all information about what types of Errors the function returns in favor if what is essentially a trait object of std::error::Error seems... questionable to me. I value type safety a lot.
TL;DR: It's Java's explicit throw declarations with extra steps, and syntactic sugar to make the totally-not-exceptions work kinda like exceptions.