jwks-client icon indicating copy to clipboard operation
jwks-client copied to clipboard

Error doesn't handle backtrace

Open naokiri opened this issue 5 years ago • 0 comments

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> {
        // ...
    }
}

naokiri avatar Oct 19 '20 06:10 naokiri