Return Option from Contact::add_or_lookup()

This allows to distinguish exceptions,
such as database errors, from invalid user input.
For example, if the From: field of the message
does not look like an email address, the mail
should be ignored. But if there is a database
failure while writing a new contact for the address,
this error should be bubbled up.
This commit is contained in:
link2xt
2023-01-09 22:28:06 +00:00
parent 5ae6c25394
commit e215b4d919
13 changed files with 176 additions and 56 deletions

View File

@@ -368,6 +368,7 @@ Can we chat at 1pm pacific, today?"
let bob_id = Contact::add_or_lookup(&alice, "", "bob@example.net", Origin::ManuallyCreated)
.await?
.unwrap()
.0;
let bob_reaction = reactions.get(bob_id);
assert!(bob_reaction.is_empty()); // Bob has not reacted to message yet.