From 87d5b56e4f80dee38f75834e58de12e2d8b76555 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Sat, 26 Oct 2024 03:31:24 +0200 Subject: [PATCH] Box Octocrab error as it is too large (#1543) --- lychee-lib/src/client.rs | 6 +++--- lychee-lib/src/types/error.rs | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lychee-lib/src/client.rs b/lychee-lib/src/client.rs index 49c652a..4ba97b2 100644 --- a/lychee-lib/src/client.rs +++ b/lychee-lib/src/client.rs @@ -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 diff --git a/lychee-lib/src/types/error.rs b/lychee-lib/src/types/error.rs index 286332f..86faacb 100644 --- a/lychee-lib/src/types/error.rs +++ b/lychee-lib/src/types/error.rs @@ -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), /// 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), /// 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), } }