Box Octocrab error as it is too large (#1543)

This commit is contained in:
Matthias Endler 2024-10-26 03:31:24 +02:00 committed by GitHub
parent 998ef6c080
commit 87d5b56e4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 9 deletions

View file

@ -364,9 +364,9 @@ impl ClientBuilder {
Octocrab::builder()
.personal_token(token.to_string())
.build()
// this is essentially the same reqwest::ClientBuilder::build error
// this is essentially the same `reqwest::ClientBuilder::build` error
// see https://docs.rs/octocrab/0.18.1/src/octocrab/lib.rs.html#360-364
.map_err(ErrorKind::BuildGithubClient)?,
.map_err(|e: octocrab::Error| ErrorKind::BuildGithubClient(Box::new(e)))?,
),
_ => None,
};
@ -638,7 +638,7 @@ impl Client {
};
let repo = match client.repos(&uri.owner, &uri.repo).get().await {
Ok(repo) => repo,
Err(e) => return ErrorKind::GithubRequest(e).into(),
Err(e) => return ErrorKind::GithubRequest(Box::new(e)).into(),
};
if let Some(true) = repo.private {
// The private repo exists. Assume a given endpoint exists as well

View file

@ -26,7 +26,7 @@ pub enum ErrorKind {
/// Network error while using GitHub API
#[error("Network error (GitHub client)")]
GithubRequest(#[from] octocrab::Error),
GithubRequest(#[from] Box<octocrab::Error>),
/// Error while executing a future on the Tokio runtime
#[error("Task failed to execute to completion")]
@ -46,7 +46,7 @@ pub enum ErrorKind {
/// The GitHub client required for making requests cannot be created
#[error("Error creating GitHub client")]
BuildGithubClient(#[source] octocrab::Error),
BuildGithubClient(#[source] Box<octocrab::Error>),
/// Invalid GitHub URL
#[error("GitHub URL is invalid: {0}")]
@ -168,10 +168,13 @@ impl ErrorKind {
Some(utils::reqwest::trim_error_output(e))
}
}
ErrorKind::GithubRequest(e) => match e {
octocrab::Error::GitHub { source, .. } => Some(source.message.to_string()),
_ => None,
},
ErrorKind::GithubRequest(e) => {
if let octocrab::Error::GitHub { source, .. } = &**e {
Some(source.message.clone())
} else {
None
}
}
_ => self.source().map(ToString::to_string),
}
}