Skip to content

Commit

Permalink
fix: bail
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanaden committed Jun 29, 2024
1 parent cbbed38 commit fb67bf5
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions rm-main/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fs::File, io::Read};

use anyhow::Result;
use anyhow::{bail, Result};
use base64::Engine;
use clap::{Parser, Subcommand};
use regex::Regex;
Expand Down Expand Up @@ -70,16 +70,8 @@ async fn fetch_rss(config: &Config, url: &str, filter: Option<&str>) -> Result<(
let channel = rss::Channel::read_from(&content[..])?;
let re: Option<Regex> = {
if let Some(filter_str) = filter {
let res = Regex::new(&format!(r"{filter_str}"));
match res {
Err(e) => {
eprintln!(
"error constructing regex: {e}\nCheck if provided regex filter is valid."
);
std::process::exit(1);
}
Ok(re) => Some(re),
}
let res = Regex::new(&format!(r"{filter_str}"))?;
Some(res)
} else {
None
}
Expand All @@ -88,10 +80,7 @@ async fn fetch_rss(config: &Config, url: &str, filter: Option<&str>) -> Result<(
if let (Some(title), Some(url)) = (item.title(), item.link()) {
if let Some(re) = &re {
if re.is_match(title) {
println!("{title} matches provided regex");
return Some((title, url));
} else {
println!("{title} does not match provided regex");
}
} else {
return Some((title, url));
Expand All @@ -106,12 +95,7 @@ async fn fetch_rss(config: &Config, url: &str, filter: Option<&str>) -> Result<(
..Default::default()
};
if let Err(e) = transclient.torrent_add(args).await {
eprintln!("error while adding a torrent: {e}");
if e.to_string().contains("expected value at line") {
eprintln!("Check whether your arguments are valid.");
}

std::process::exit(1);
bail!("error while adding a torrent: {e}")
}
}
Ok(())
Expand Down

0 comments on commit fb67bf5

Please sign in to comment.