As a side note, I've found that getting used to `Result` actually gives an added benefit of getting comfortable with the idea of such computational contexts in general. Be it Options, Maybes, Futures, Promises, Haskell IO, or anything of that kind.
As a side note, I've found that getting used to `Result` actually gives an added benefit of getting comfortable with the idea of such computational contexts in general. Be it Options, Maybes, Futures, Promises, Haskell IO, or anything of that kind.
And as the executable gets larger and refactored, some of the "executable" code will inevitably become "library" code. What then?
Then that is migrated to `thiserror` (or something bespoke) at the same time as it's migrated to the library context.
The library / executable is the delineation between providing a Rust-level API for third parties versus consuming such APIs.
If you're providing a Rust API, you want to provide precise error so that the user is able to precisely target and handle errors if they need to.
If you're only consuming Rust APIs, then you want to precisely handle some of the errors you get, and just chuck the rest over the side.
You can continue returning `anyhow::Error`, wrap it into a newtype error for your library, or refactor to use thiserror. Thanks to the `?` operator and Rust's type aliases, you can get away with very few code changes to switch between these!
But! To each their own!
For example, if I wanted to say, return a 500 status code for all diesel database errors, I can convert the diesel error into my custom error type, then throw it back up the stack using `anyhow`. This works _really_ well in conjunction with Rocket's Responder impl.
EDIT: This is pretty close to what TFA is saying as well, I should have read more in the article, heh
You can absolutely do that if you want, it's just that usually when writing an executable you don't care about creating the precise error types thiserror provides (especially doing so executable-wide), you'd handle the errors you get from reqwest or sqlx or whatever when you get them, and those you don't handle you just want to bubble up to an executable-wide handler.