diff --git a/src/main.rs b/src/main.rs index 7679390..784b0c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ async fn main() { .enable_io() .enable_time() .build() - .unwrap(); + .expect("Can't build tokio runtime."); loop { let start = Instant::now(); diff --git a/src/revanced.rs b/src/revanced.rs index 7726b80..380cb23 100644 --- a/src/revanced.rs +++ b/src/revanced.rs @@ -20,7 +20,7 @@ async fn search() -> Option { let latest_version = { let mut tag = github_latest_version.tag_name.chars(); tag.next(); - Version::parse(tag.as_str()).unwrap() + Version::parse(tag.as_str()).expect("Can't parse the latest version") }; if let Some(current_version) = get_current_version() { @@ -41,7 +41,10 @@ async fn search() -> Option { format!( "{}://{}{}", asset.browser_download_url.scheme(), - asset.browser_download_url.host().unwrap(), + asset + .browser_download_url + .host() + .expect("Can't get asset host"), asset.browser_download_url.path() ) }) @@ -68,9 +71,19 @@ fn get_current_version() -> Option { } Ok(paths) => { for path in paths { - let re = Regex::new(r"revanced-patches-(?P\d+\.\d+\.\d+)\.jar").unwrap(); - if let Some(caps) = re.captures(&path.unwrap().path().display().to_string()) { - return Some(Version::parse(&caps["version"]).unwrap()); + let re = Regex::new(r"revanced-patches-(?P\d+\.\d+\.\d+)\.jar") + .expect("Can't build regex formula for revanced patches."); + if let Some(caps) = re.captures( + &path + .expect("Can't match patterns for revanced patches") + .path() + .display() + .to_string(), + ) { + return Some( + Version::parse(&caps["version"]) + .expect("No version found in the asset of revanced patches"), + ); } } None diff --git a/src/utils.rs b/src/utils.rs index 1422f4d..af68201 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,7 +11,7 @@ pub fn get_data_directory() -> PathBuf { /// Download a file to data directory pub async fn download_file(url: String) { - let source = reqwest::Url::parse(&url).unwrap(); + let source = reqwest::Url::parse(&url).expect("Can't parse the URL"); let fname = source .path_segments() .and_then(|segments| segments.last()) @@ -24,10 +24,12 @@ pub async fn download_file(url: String) { let filepath = get_data_directory().join(fname); // Create file - let mut dest = File::create(filepath).unwrap(); + let mut dest = File::create(&filepath) + .unwrap_or_else(|_| panic!("Can't create the file at {}.", filepath.display())); // Write data to the file - dest.write_all(&bytes).unwrap(); + dest.write_all(&bytes) + .unwrap_or_else(|_| panic!("Can't write to file at {}.", filepath.display())); } Err(..) => eprintln!("Can't download {}.", fname), },