Skip to content

Commit

Permalink
handle failed castings by erroring out
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp committed Oct 3, 2023
1 parent 8ee409a commit 61133ab
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions base_layer/contacts/src/contacts_service/storage/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,27 @@ where T: ContactsBackend + 'static
delivery_confirmation: Option<u64>,
read_confirmation: Option<u64>,
) -> Result<(), ContactsServiceStorageError> {
let mut delivery = None;
if let Some(timestamp) = delivery_confirmation {
let secs = i64::try_from(timestamp).map_err(|_e| ContactsServiceStorageError::ConversionError)?;
delivery = Some(
NaiveDateTime::from_timestamp_opt(secs, 0)
.ok_or_else(|| ContactsServiceStorageError::ConversionError)?,
)
};

let mut read = None;
if let Some(timestamp) = read_confirmation {
let secs = i64::try_from(timestamp).map_err(|_e| ContactsServiceStorageError::ConversionError)?;
read = Some(
NaiveDateTime::from_timestamp_opt(secs, 0)
.ok_or_else(|| ContactsServiceStorageError::ConversionError)?,
)
};

self.db
.write(WriteOperation::Upsert(Box::new(DbKeyValuePair::MessageConfirmations(
message_id,
delivery_confirmation
.map(|d| NaiveDateTime::from_timestamp_opt(i64::try_from(d).unwrap_or(0), 0).unwrap()),
read_confirmation.map(|d| NaiveDateTime::from_timestamp_opt(i64::try_from(d).unwrap_or(0), 0).unwrap()),
message_id, delivery, read,
))))?;

Ok(())
Expand Down

0 comments on commit 61133ab

Please sign in to comment.