Skip to content

Commit

Permalink
gracefully handle bad mergeCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Jul 12, 2023
1 parent 3108321 commit 69ec6e9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,14 +1129,20 @@ function mergeCollection(collectionKey, collection) {
}

// Confirm all the collection keys belong to the same parent
let hasCollectionKeyCheckFailed = false;
_.each(collection, (_data, dataKey) => {
if (isKeyMatch(collectionKey, dataKey)) {
return;
}

throw new Error(`Provided collection doesn't have all its data belonging to the same parent. CollectionKey: ${collectionKey}, DataKey: ${dataKey}`);
hasCollectionKeyCheckFailed = true;
Logger.logError(`Provided collection doesn't have all its data belonging to the same parent. CollectionKey: ${collectionKey}, DataKey: ${dataKey}`);
});

// Gracefully handle bad mergeCollection updates so it doesn't block the merge queue
if (hasCollectionKeyCheckFailed) {
return Promise.resolve();
}

return getAllKeys()
.then((persistedKeys) => {
// Split to keys that exist in storage and keys that don't
Expand Down

0 comments on commit 69ec6e9

Please sign in to comment.