diff --git a/CHANGELOG.md b/CHANGELOG.md index 1345150..133233d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ available [on GitHub][2]. Adds a `--path` option to the `default-config` command to print default config location intead (by [@zixuanzhang-x][zixuanzhang-x]) +* [#128](/~https://github.com/chshersh/tool-sync/issues/128) + Adds new error message RepoError::NotFound when fetch_release_info + returns 404 + (by [@crudiedo][crudiedo]) ### Fixed diff --git a/src/model.rs b/src/model.rs index ccab5fd..7d05757 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,4 +1,5 @@ pub mod asset_name; pub mod os; pub mod release; +pub mod repo; pub mod tool; diff --git a/src/model/repo.rs b/src/model/repo.rs new file mode 100644 index 0000000..ec6eceb --- /dev/null +++ b/src/model/repo.rs @@ -0,0 +1,29 @@ +use crate::model::tool::ToolInfoTag; +use std::fmt::{Display, Formatter}; + +#[derive(Debug, PartialEq, Eq)] +pub enum RepoError { + /// Either repository or tag is not found due to misconfiguration + NotFound { + owner: String, + repo: String, + tag: ToolInfoTag, + }, +} + +impl Display for RepoError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + RepoError::NotFound { owner, repo, tag } => match tag { + ToolInfoTag::Latest => { + write!(f, "The {owner}/{repo} doesn't exist or has no releases.") + } + _ => write!( + f, + "The {owner}/{repo} doesn't exist or {tag} was not found.", + tag = tag.to_str_version() + ), + }, + } + } +} diff --git a/src/sync/prefetch.rs b/src/sync/prefetch.rs index 78d6793..3580c7b 100644 --- a/src/sync/prefetch.rs +++ b/src/sync/prefetch.rs @@ -8,6 +8,7 @@ use super::configure::configure_tool; use crate::config::schema::ConfigAsset; use crate::infra::client::Client; use crate::model::release::AssetError; +use crate::model::repo::RepoError; use crate::model::tool::{Tool, ToolAsset}; const PREFETCH: Emoji<'_, '_> = Emoji("🔄 ", "-> "); @@ -133,7 +134,18 @@ fn prefetch_tool( match client.fetch_release_info() { Err(e) => { - prefetch_progress.unexpected_err_msg(tool_name, e); + if let Some(ureq::Error::Status(404, _)) = e.downcast_ref::() { + prefetch_progress.unexpected_err_msg( + tool_name, + RepoError::NotFound { + owner: tool_info.owner, + repo: tool_info.repo, + tag: tool_info.tag, + }, + ); + } else { + prefetch_progress.unexpected_err_msg(tool_name, e); + } // do some other processing prefetch_progress.update_message(already_completed); None