Skip to content

Commit 7209d8c

Browse files
author
Floris Bruynooghe
committed
Propagate the source of errors via thiserror
This makes the std::error::Error::source() report the original error, allowing "reporting types" like anyhow::Error to display the entire error chain nicely.
1 parent a49941b commit 7209d8c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/error.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ pub enum Error {
1818
/// Error in underlying RustTLS library.
1919
/// Might signal problem with establishing secure connection using trusted certificates
2020
#[error("TLS error")]
21-
TLSError(rustls::Error),
21+
TLSError(#[source] rustls::Error),
2222

2323
/// Error when establishing connection to OAuth server
2424
#[error("Could not establish connection with OAuth server")]
25-
OAuthConnectionError(hyper::Error),
25+
OAuthConnectionError(#[source] hyper::Error),
2626

2727
/// Error when parsing response from OAuth server
2828
#[error("Could not parse OAuth server response")]
29-
OAuthParsingError(serde_json::error::Error),
29+
OAuthParsingError(#[source] serde_json::error::Error),
3030

3131
/// Variable `GOOGLE_APPLICATION_CREDENTIALS` could not be found in the current environment
3232
///
@@ -39,33 +39,33 @@ pub enum Error {
3939
///
4040
/// Path has to be defined using `GOOGLE_APPLICATION_CREDENTIALS` environment variable
4141
#[error("Environment variable `GOOGLE_APPLICATION_CREDENTIALS` contains invalid path to application profile file")]
42-
ApplicationProfilePath(std::io::Error),
42+
ApplicationProfilePath(#[source] std::io::Error),
4343

4444
/// Wrong format of custom application profile
4545
///
4646
/// Application profile is downloaded from GCP console and is stored in filesystem on the server.
4747
/// Full path is passed to library by setting `GOOGLE_APPLICATION_CREDENTIALS` variable with path as a value.
4848
#[error("Application profile provided in `GOOGLE_APPLICATION_CREDENTIALS` was not parsable")]
49-
ApplicationProfileFormat(serde_json::error::Error),
49+
ApplicationProfileFormat(#[source] serde_json::error::Error),
5050

5151
/// Default user profile not found
5252
///
5353
/// User can authenticate locally during development using `gcloud auth login` which results in creating
5454
/// `~/.config/gcloud/application_default_credentials.json` which couldn't be find on the machine
5555
#[error("User authentication profile not found")]
56-
UserProfilePath(std::io::Error),
56+
UserProfilePath(#[source] std::io::Error),
5757

5858
/// Wrong format of user profile
5959
#[error("User profile was not parsable")]
60-
UserProfileFormat(serde_json::error::Error),
60+
UserProfileFormat(#[source] serde_json::error::Error),
6161

6262
/// Could not connect to server
6363
#[error("Could not establish connection with server")]
64-
ConnectionError(hyper::Error),
64+
ConnectionError(#[source] hyper::Error),
6565

6666
/// Could not parse response from server
6767
#[error("Could not parse server response")]
68-
ParsingError(serde_json::error::Error),
68+
ParsingError(#[source] serde_json::error::Error),
6969

7070
/// Could not connect to server
7171
#[error("Server unavailable: {0}")]

0 commit comments

Comments
 (0)