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 */
DebouncedEvent::NoticeRemove(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) => panic!(format!(
"mbox folder {} was renamed to {}.",
src.display(),
dest.display()
)),
/* Trigger rescan of folder */
DebouncedEvent::Rename(src, dest) => {
if folders.lock().unwrap().values().any(|f| &f.path == &src) {
let folder_hash = get_path_hash!(&src);
sender.send(RefreshEvent {
hash: folder_hash,
kind: RefreshEventKind::Failure(MeliError::new(format!(
"mbox folder {} was renamed to {}.",
src.display(),
dest.display()
))),
});
return;
}
}
/* Trigger rescan of folders */
DebouncedEvent::Rescan => {
/* Actually should rescan all folders */
unreachable!("Unimplemented: rescan of all folders in MboxType")
for h in folders.lock().unwrap().keys() {
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 =
unsafe { notmuch_query_create(*database_lck, query_str.as_ptr()) };
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 status =
unsafe { notmuch_query_search_messages(query, &mut messages as *mut _) };
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());
let iter = MessageIterator { messages };

View File

@ -901,7 +901,7 @@ pub fn phrase(input: &[u8]) -> IResult<&[u8], Vec<u8>> {
);
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 */
ascii_e = input[ascii_s..]
.find(b" ")

View File

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