jwks-client
jwks-client copied to clipboard
Error doesn't handle backtrace
This issue is for future Rust change expected in https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md
Current error doesn't have reference to the source of the error, even when there's a cause. We must add a source into some types of error which has error reason in the depending libraries.
If we keep the Error as struct, the source will be an optional field that depends on type. This will be less easy to handle. I would suggest to change the structure of Error to be an enum like below.
#[derive(Debug)]
pub enum Error {
Invalid {msg: String},
Connection{msg: String, source: reqwest::Error},
// ...etc, etc.
}
impl From<request::Error> for Error {
// ...
}
// In the future version of Rust
impl std::error::Error for Error {
fn backtrace(&self) -> Option<&Backtrace> {
// ...
}
fn source(&self) -> Option<&dyn Error + 'static> {
// ...
}
}