Replace some panics with errors

jmap
Manos Pitsidianakis 2019-11-27 14:23:35 +02:00
parent ba52c59859
commit 58209d6f6b
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 48 additions and 13 deletions

View File

@ -520,18 +520,46 @@ impl MailBackend for MboxType {
/* Remove */ /* Remove */
DebouncedEvent::NoticeRemove(pathbuf) DebouncedEvent::NoticeRemove(pathbuf)
| DebouncedEvent::Remove(pathbuf) => { | DebouncedEvent::Remove(pathbuf) => {
panic!(format!("mbox folder {} was removed.", pathbuf.display())) if folders
.lock()
.unwrap()
.values()
.any(|f| &f.path == &pathbuf)
{
let folder_hash = get_path_hash!(&pathbuf);
sender.send(RefreshEvent {
hash: folder_hash,
kind: RefreshEventKind::Failure(MeliError::new(format!(
"mbox folder {} was removed.",
pathbuf.display()
))),
});
return;
}
} }
/* Envelope hasn't changed */ DebouncedEvent::Rename(src, dest) => {
DebouncedEvent::Rename(src, dest) => panic!(format!( if folders.lock().unwrap().values().any(|f| &f.path == &src) {
"mbox folder {} was renamed to {}.", let folder_hash = get_path_hash!(&src);
src.display(), sender.send(RefreshEvent {
dest.display() hash: folder_hash,
)), kind: RefreshEventKind::Failure(MeliError::new(format!(
/* Trigger rescan of folder */ "mbox folder {} was renamed to {}.",
src.display(),
dest.display()
))),
});
return;
}
}
/* Trigger rescan of folders */
DebouncedEvent::Rescan => { DebouncedEvent::Rescan => {
/* Actually should rescan all folders */ for h in folders.lock().unwrap().keys() {
unreachable!("Unimplemented: rescan of all folders in MboxType") sender.send(RefreshEvent {
hash: *h,
kind: RefreshEventKind::Rescan,
});
}
return;
} }
_ => {} _ => {}
}, },

View File

@ -216,13 +216,17 @@ impl MailBackend for NotmuchDb {
let query: *mut notmuch_query_t = let query: *mut notmuch_query_t =
unsafe { notmuch_query_create(*database_lck, query_str.as_ptr()) }; unsafe { notmuch_query_create(*database_lck, query_str.as_ptr()) };
if query.is_null() { if query.is_null() {
panic!("Out of memory."); tx.send(AsyncStatus::Payload(Err(MeliError::new("Could not create query. Out of memory?")))).unwrap();
tx.send(AsyncStatus::Finished).unwrap();
return;
} }
let mut messages: *mut notmuch_messages_t = std::ptr::null_mut(); let mut messages: *mut notmuch_messages_t = std::ptr::null_mut();
let status = let status =
unsafe { notmuch_query_search_messages(query, &mut messages as *mut _) }; unsafe { notmuch_query_search_messages(query, &mut messages as *mut _) };
if status != 0 { if status != 0 {
panic!(status); tx.send(AsyncStatus::Payload(Err(MeliError::new("Search for {} returned {}", folder.query_str.as_str(), status)))).unwrap();
tx.send(AsyncStatus::Finished).unwrap();
return;
} }
assert!(!messages.is_null()); assert!(!messages.is_null());
let iter = MessageIterator { messages }; let iter = MessageIterator { messages };

View File

@ -901,7 +901,7 @@ pub fn phrase(input: &[u8]) -> IResult<&[u8], Vec<u8>> {
); );
break; break;
} }
if ascii_s == ascii_e { if ascii_s >= ascii_e {
/* We have the start of an encoded word but not the end, so parse it as ascii */ /* We have the start of an encoded word but not the end, so parse it as ascii */
ascii_e = input[ascii_s..] ascii_e = input[ascii_s..]
.find(b" ") .find(b" ")

View File

@ -962,6 +962,9 @@ impl Threads {
.get(envelopes_lck[&env_hash].message_id().raw()) .get(envelopes_lck[&env_hash].message_id().raw())
.cloned() .cloned()
{ {
if self.thread_nodes[&id].message.is_some() {
return false;
}
self.thread_nodes.entry(id).and_modify(|n| { self.thread_nodes.entry(id).and_modify(|n| {
n.message = Some(env_hash); n.message = Some(env_hash);
n.date = envelopes_lck[&env_hash].date(); n.date = envelopes_lck[&env_hash].date();