diff --git a/src/api.rs b/src/api.rs index 15c6422..595974f 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,16 +1,10 @@ /// Parse infohash from the source filepath, -/// decode JSON to array on success -pub fn infohashes(path: &str) -> anyhow::Result> { +/// decode JSON to array on success, return None if the feed is damaged (incomplete) +pub fn infohashes(path: &str) -> anyhow::Result>> { if path.contains("://") { todo!("URL sources yet not supported") } - let mut f = std::fs::File::open(path)?; - let mut s = String::new(); - - use std::io::Read; - f.read_to_string(&mut s)?; - - let r: Vec = serde_json::from_str(&s)?; - + let s = std::fs::read_to_string(path)?; + let r: Option> = serde_json::from_str(&s).ok(); Ok(r) } diff --git a/src/main.rs b/src/main.rs index e94f8f1..fee941f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,16 @@ async fn main() -> Result<()> { // * aquatic server may update the stats at this moment, handle result manually match api::infohashes(source) { Ok(infohashes) => { - for i in infohashes { + for i in match infohashes { + Some(h) => h, + None => { + // skip without panic + debug.error(&format!( + "The feed `{source}` has an incomplete format (or is still updating); skip." + )); + continue; + } + } { // is already indexed? if index.has(&i) { continue;