Why Use Structured #Errors in #Rust Applications?
https://home.expurple.me/posts/why-use-structured-errors-in-rust-applications/
Why Use Structured #Errors in #Rust Applications?
https://home.expurple.me/posts/why-use-structured-errors-in-rust-applications/
I was struggeling to report the source cause of an error in a #rust codebase!
The #thiserror crate and #miette crate seemed to be the right set of tools for this.
Although it hasn't been easy to figure out!
( but I didn't even cry 😏)
Once you master both, error reporting in #rust becomes fun, standardized, colorful and painless!
Interesting read about #snafu vs #thiserror: https://medium.com/@greptime_team/error-handling-for-large-rust-projects-a-deep-dive-into-5e10ee4cbc96
The stack_trace_debug macro proposed reminds me strongly of the error_chain construct in chapter 8 of @algo_luca's Zero To Production In Rust. https://www.zero2prod.com/index.html
@greysemanticist It works, because thiserror generates a From impl for rusqlite::Error for your AuthError (due to the #[from] attribute).
And ? will use that From impl to return AuthError.
See also the std #Rust docs on how ? works:
"When applied to values of the Result<T, E> type, it propagates errors. If the value is Err(e), then it will return Err(From::from(e)) from the enclosing function or closure."
https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator
#thiserror and ? can look like magic, but it's just #RustLang