Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
chore: Handle error when no download link is found
Browse files Browse the repository at this point in the history
  • Loading branch information
rabilrbl committed May 25, 2024
1 parent 93412af commit dc60af0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/apkmirror/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::errors::DownApkError;
use crate::utils::selector;
use clap::ValueEnum;
use console::Emoji;
use core::time::Duration;
use indicatif::{ProgressBar, ProgressStyle};
Expand All @@ -9,7 +10,6 @@ use scraper::Html;
use std::cmp::min;
use tokio::fs::File;
use tokio::io::AsyncWriteExt;
use clap::ValueEnum;

static LOOKING_GLASS: Emoji<'_, '_> = Emoji("🔍 ", "");
static SPARKLE: Emoji<'_, '_> = Emoji("✨ ", ":-)");
Expand Down Expand Up @@ -538,10 +538,10 @@ impl ApkMirror {
version,
download_link: match self.download_link(&download_link, &pb).await {
Ok(download_link) => download_link,
Err(e) => panic!(
"Something went wrong while getting download link. Err: {}",
e
),
Err(_) => {
println!("Could not get download link for {}", download_link);
continue;
}
},
apk_type: ApkType::from(badge_text),
arch,
Expand Down Expand Up @@ -640,10 +640,10 @@ impl ApkMirror {
));
final_download_link.to_string()
}
None => panic!("No download link found"),
None => Err(DownApkError::from("No final download link found"))?,
}
}
None => panic!("No download link found"),
None => Err(DownApkError::from("No download link found"))?,
};
pb.set_message("Finished getting download link");
Ok(final_download_link)
Expand Down
6 changes: 6 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ impl From<String> for DownApkError<'_> {
}
}

impl From<&str> for DownApkError<'_> {
fn from(e: &str) -> Self {
DownApkError::Other(e.to_string())
}
}

impl From<std::io::Error> for DownApkError<'_> {
fn from(e: std::io::Error) -> Self {
DownApkError::IoError(e)
Expand Down

0 comments on commit dc60af0

Please sign in to comment.