Compare commits

..

2 Commits

Author SHA1 Message Date
Thomas Eppers
ebf1a7726e fixed regex string 2021-09-09 15:23:55 +02:00
Thomas Eppers
0786c26260 added fix for json with a count of 0 2021-09-09 15:14:24 +02:00
2 changed files with 12 additions and 1 deletions

View File

@ -20,6 +20,7 @@ pub struct Images {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Tags { pub struct Tags {
count: usize,
#[serde(rename(deserialize = "next"))] #[serde(rename(deserialize = "next"))]
next_page: Option<String>, next_page: Option<String>,
#[serde(rename(deserialize = "previous"))] #[serde(rename(deserialize = "previous"))]
@ -29,9 +30,14 @@ pub struct Tags {
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
/// repo string contains an illegal character
InvalidCharacter(char), InvalidCharacter(char),
/// couldn't fetch json with reqwest
Fetching(String), Fetching(String),
/// a serde error
Converting(String), Converting(String),
/// invalid repos show a valid json with 0 tags
NoTagsFound,
NoPrevPage, NoPrevPage,
NoNextPage, NoNextPage,
} }
@ -44,6 +50,7 @@ impl fmt::Display for Error {
Error::Converting(s) => write!(f, "Converting error: {}", s), Error::Converting(s) => write!(f, "Converting error: {}", s),
Error::NoNextPage => write!(f, "No next page available"), Error::NoNextPage => write!(f, "No next page available"),
Error::NoPrevPage => write!(f, "No previous page available"), Error::NoPrevPage => write!(f, "No previous page available"),
Error::NoTagsFound => write!(f, "Given Repo has 0 tags. Is it valid?"),
} }
} }
} }
@ -69,6 +76,10 @@ impl Tags {
Err(e) => return Err(Error::Converting(format!("invalid json: {}", e))), Err(e) => return Err(Error::Converting(format!("invalid json: {}", e))),
}; };
if tags.count == 0 {
return Err(Error::NoTagsFound);
}
Ok(tags) Ok(tags)
} }

View File

@ -47,7 +47,7 @@ impl ServiceSwitcher {
Self { Self {
list, list,
state: ListState::default(), state: ListState::default(),
regex: Regex::new(r"( *image *): *(.*):([.*]??) *").unwrap(), regex: Regex::new(r"( *image *): *([^:]*):?([^:]?) *").unwrap(),
changed: false, changed: false,
} }
} }