aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2017-11-13 01:50:33 -0800
committeriximeow <me@iximeow.net>2017-11-13 01:50:33 -0800
commit84de78e2282c51027fa59ed26a709f4033ccc760 (patch)
tree865b98e8cfd4ca264b2aecc614dc8030b417a3f1
parentfcc94f8705ee0b604af25958668c30f79c3dec1d (diff)
inform me when the tweet cache cant be loaded
-rw-r--r--src/display/mod.rs4
-rw-r--r--src/tw/mod.rs16
2 files changed, 15 insertions, 5 deletions
diff --git a/src/display/mod.rs b/src/display/mod.rs
index 8760f4a..7233f75 100644
--- a/src/display/mod.rs
+++ b/src/display/mod.rs
@@ -217,7 +217,9 @@ pub fn paint(tweeter: &mut ::tw::TwitterCache) -> Result<(), std::io::Error> {
wrapped.into_iter().rev().collect()
},
Infos::DM(msg) => {
- vec![format!("{}{}DM: {}", cursor::Goto(1, height - h), clear::CurrentLine, msg)]
+ let mut lines = vec![format!("{}{}{} DM:", cursor::Goto(1, height - h), clear::CurrentLine, "from")];
+ lines.push(msg);
+ lines
}
Infos::User(user) => {
vec![
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<Tweet, serde_json::Error> = 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<User, serde_json::Error> = 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;