From 672d50899438788e5656169e28a104b72563cb6b Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Mon, 13 Nov 2017 01:50:33 -0800 Subject: inform me when the tweet cache cant be loaded --- src/tw/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/tw') diff --git a/src/tw/mod.rs b/src/tw/mod.rs index 5a3cdfc..08ec974 100644 --- a/src/tw/mod.rs +++ b/src/tw/mod.rs @@ -406,12 +406,20 @@ impl TwitterCache { let mut cache: TwitterCache = result; cache.tweets = HashMap::new(); for line in BufReader::new(File::open(TwitterCache::TWEET_CACHE).unwrap()).lines() { - let t: Tweet = serde_json::from_str(&line.unwrap()).unwrap(); - cache.number_and_insert_tweet(t); + let unwrapped_line = line.unwrap(); + let t: Result = serde_json::from_str(&unwrapped_line.clone()); + match t { + Ok(tweet) => cache.number_and_insert_tweet(tweet), + Err(e) => panic!(format!("{} on line {} - {:?}", e, cache.tweets.len(), unwrapped_line.clone())) + }; } for line in BufReader::new(File::open(TwitterCache::USERS_CACHE).unwrap()).lines() { - let u: User = serde_json::from_str(&line.unwrap()).unwrap(); - cache.users.insert(u.id.to_owned(), u); + let unwrapped_line = line.unwrap(); + let u: Result = serde_json::from_str(&unwrapped_line.clone()); + match u { + Ok(user) => cache.users.insert(user.id.to_owned(), user), + Err(e) => panic!(format!("{} on line {} - {:?}", e, cache.users.len(), unwrapped_line.clone())) + }; } cache.caching_permitted = true; cache.needs_save = false; -- cgit v1.1