+use chrono::{DateTime, Utc};
use reqwest::Url;
use std::collections::{HashMap, HashSet, VecDeque};
use std::fs::File;
extend_future: Option<HashMap<String, String>>,
}
+#[derive(Debug)]
+pub struct ErrorLog {
+ items: VecDeque<(ClientError, DateTime<Utc>)>,
+ origin: isize,
+}
+
+impl ErrorLog {
+ fn new() -> Self {
+ ErrorLog {
+ items: VecDeque::new(),
+ origin: 0, // FIXME: eventually prune these at the front
+ }
+ }
+
+ pub fn push_now(&mut self, error: ClientError) {
+ self.items.push_back((error, Utc::now()));
+ }
+
+ pub fn get_bounds(&self) -> (isize, isize) {
+ (self.origin, self.origin + self.items.len() as isize)
+ }
+
+ pub fn get(&self, index: isize) -> (ClientError, DateTime<Utc>) {
+ self.items[(index - self.origin) as usize].clone()
+ }
+}
+
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Followness {
NotFollowing,
instance: Option<Instance>,
permit_write: bool,
logfile: Option<File>,
+ error_log: ErrorLog,
}
#[derive(Debug, PartialEq, Eq, Clone)]
instance: None,
permit_write: false,
logfile: None,
+ error_log: ErrorLog::new(),
})
}
Err(ClientError::from_response(urlstr, rsp))
}
}
+
+ pub fn add_to_error_log(&mut self, err: ClientError) {
+ self.error_log.push_now(err);
+ }
}
),
// FIXME: it would be nice to discriminate errors
- // better here, and maybe return anything worse
- // than 'user not found' to the Error Log
- Err(_) => LogicalAction::PopOverlayBeep,
+ // better here, and do something a bit less
+ // terrifying for plain "account not found", like
+ // allowing the user to re-edit
+ Err(err) => LogicalAction::Error(err),
}
}
}),
),
// FIXME: it would be nice to discriminate errors
- // better here, and maybe return anything worse
- // than 'post not found' to the Error Log
- Err(_) => LogicalAction::PopOverlayBeep,
+ // better here, and do something a bit less
+ // terrifying for plain "status not found", like
+ // allowing the user to re-edit
+ Err(err) => LogicalAction::Error(err),
}
}
}),
match client.post_status(&self.post) {
Ok(_) => LogicalAction::Pop,
- Err(_) => LogicalAction::Beep, // FIXME: report the error!
+
+ // FIXME: if we can identify errors of the form "refusal
+ // to post because of something the user can reasonably
+ // fix", we should stay in this menu and let them retry
+ Err(err) => LogicalAction::Error(err),
}
}
}
vec![Todo::Stream(feeds_updated)]
}
- // FIXME: errors here should go in the Error Log
- _ => Vec::new(),
+ Err(err) => {
+ self.client.add_to_error_log(err);
+ // FIXME: throw user into the Error Log
+ Vec::new()
+ }
}
}
Ok(SubthreadEvent::LDBCheckpointTimer) => {
self.pop_overlay_activity();
self.activity_state_mut().got_search_expression(dir, regex)
}
- LogicalAction::Error(_) => break PhysicalAction::Beep, // FIXME: Error Log
+ LogicalAction::Error(err) => {
+ client.add_to_error_log(err);
+ break PhysicalAction::Beep;
+ }
LogicalAction::PostComposed(post) => {
let newact = match self.activity_stack.top() {
Activity::Compose(
}
};
- result.expect("FIXME: need to implement the Error Log here")
+ match result {
+ Ok(state) => state,
+ Err(err) => {
+ client.add_to_error_log(err);
+ panic!("FIXME: need to implement the Error Log here");
+ }
+ }
}
fn save_ldb(&self) -> Result<(), TuiError> {