Skip to content

Commit

Permalink
[#128] Uses RepoError::NotFound when fetch_release_info returns 404 (#…
Browse files Browse the repository at this point in the history
…135)

Resolves #128

This PR adds a new error `RepoError::NotFound` and uses it when
fetch_release_info returns 404.

The error message depends on the tag, and could be either 
❌  **bottom** The clementtsang/bottomx doesn't exist or tags/0.66.3 was
not found.

or

❌  **bottom** The clementtsang/bottomx doesn't exist or has no releases.

if the tag is latest.

### Additional tasks

- [ ] Documentation for changes provided/changed
- [ ] Tests added
- [x] Updated CHANGELOG.md
  • Loading branch information
crudiedo authored Oct 11, 2022
1 parent f345444 commit 4796cf0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod asset_name;
pub mod os;
pub mod release;
pub mod repo;
pub mod tool;
29 changes: 29 additions & 0 deletions src/model/repo.rs
Original file line number Diff line number Diff line change
@@ -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()
),
},
}
}
}
14 changes: 13 additions & 1 deletion src/sync/prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("🔄 ", "-> ");
Expand Down Expand Up @@ -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::<ureq::Error>() {
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
Expand Down

0 comments on commit 4796cf0

Please sign in to comment.