Skip to content

Commit

Permalink
Merge pull request #41 from worldcoin/0xkitsune/handle-unexpected-dbs…
Browse files Browse the repository at this point in the history
…ync-fmt

fix(db-sync): handle unexpected db sync payload format
  • Loading branch information
Dzejkop authored Feb 21, 2024
2 parents 18fb916 + dd254ce commit 5bc4f44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,18 @@ impl Coordinator {
.receipt_handle
.context("Missing receipt handle in message")?;

let items: Vec<DbSyncPayload> = serde_json::from_str(&body)?;
let items = if let Ok(items) =
serde_json::from_str::<Vec<DbSyncPayload>>(&body)
{
items
} else {
tracing::error!(
?receipt_handle,
"Failed to parse message body"
);
continue;
};

let masks: Vec<_> =
items.into_iter().map(|item| (item.id, item.mask)).collect();

Expand Down
13 changes: 12 additions & 1 deletion src/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,18 @@ impl Participant {
.receipt_handle
.context("Missing receipt handle in message")?;

let items: Vec<DbSyncPayload> = serde_json::from_str(&body)?;
let items = if let Ok(items) =
serde_json::from_str::<Vec<DbSyncPayload>>(&body)
{
items
} else {
tracing::error!(
?receipt_handle,
"Failed to parse message body"
);
continue;
};

let shares: Vec<_> = items
.into_iter()
.map(|item| (item.id, item.share))
Expand Down

0 comments on commit 5bc4f44

Please sign in to comment.