mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 10:56:29 +03:00
feat: ensure_and_debug_assert{,_eq,_ne} macros combining debug_assert* and anyhow::ensure (#6907)
We have some debug assertions already, but we also want the corresponding errors in the release configuration so that it's not less reliable than non-optimized one. This doesn't change any function signatures, only debug assertions in functions returning `Result` are replaced. Co-authored-by: l <link2xt@testrun.org>
This commit is contained in:
@@ -44,7 +44,7 @@ use crate::simplify;
|
||||
use crate::stock_str;
|
||||
use crate::sync::Sync::*;
|
||||
use crate::tools::{self, buf_compress, remove_subject_prefix};
|
||||
use crate::{chatlist_events, location};
|
||||
use crate::{chatlist_events, ensure_and_debug_assert, ensure_and_debug_assert_eq, location};
|
||||
use crate::{contact, imap};
|
||||
|
||||
/// This is the struct that is returned after receiving one email (aka MIME message).
|
||||
@@ -1456,7 +1456,7 @@ async fn do_chat_assignment(
|
||||
false => None,
|
||||
};
|
||||
if let Some(chat) = chat {
|
||||
debug_assert!(chat.typ == Chattype::Single);
|
||||
ensure_and_debug_assert!(chat.typ == Chattype::Single);
|
||||
let mut new_protection = match verified_encryption {
|
||||
VerifiedEncryption::Verified => ProtectionStatus::Protected,
|
||||
VerifiedEncryption::NotVerified(_) => ProtectionStatus::Unprotected,
|
||||
@@ -2141,7 +2141,7 @@ RETURNING id
|
||||
// afterwards insert additional parts.
|
||||
replace_msg_id = None;
|
||||
|
||||
debug_assert!(!row_id.is_special());
|
||||
ensure_and_debug_assert!(!row_id.is_special());
|
||||
created_db_entries.push(row_id);
|
||||
}
|
||||
|
||||
@@ -2404,7 +2404,9 @@ async fn lookup_chat_by_reply(
|
||||
// lookup by reply should never be needed
|
||||
// as we can directly assign the message to the chat
|
||||
// by its group ID.
|
||||
debug_assert!(mime_parser.get_chat_group_id().is_none() || !mime_parser.was_encrypted());
|
||||
ensure_and_debug_assert!(
|
||||
mime_parser.get_chat_group_id().is_none() || !mime_parser.was_encrypted()
|
||||
);
|
||||
|
||||
// Try to assign message to the same chat as the parent message.
|
||||
let Some(parent_chat_id) = ChatId::lookup_by_message(parent) else {
|
||||
@@ -3763,7 +3765,7 @@ async fn add_or_lookup_key_contacts_by_address_list(
|
||||
}
|
||||
}
|
||||
|
||||
debug_assert_eq!(contact_ids.len(), address_list.len());
|
||||
ensure_and_debug_assert_eq!(contact_ids.len(), address_list.len(),);
|
||||
Ok(contact_ids)
|
||||
}
|
||||
|
||||
@@ -3917,7 +3919,7 @@ async fn lookup_key_contacts_by_address_list(
|
||||
contact_ids.push(contact_id);
|
||||
}
|
||||
}
|
||||
debug_assert_eq!(address_list.len(), contact_ids.len());
|
||||
ensure_and_debug_assert_eq!(address_list.len(), contact_ids.len(),);
|
||||
Ok(contact_ids)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user