From 69ec6e93af68b87ffcc3e946bd09b36a03c0b74b Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 12 Jul 2023 13:41:23 -0600 Subject: [PATCH] gracefully handle bad mergeCollection --- lib/Onyx.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index a2f14c29..dbfb4899 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -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