From df5f1a5fdbe641c4914b65f99fd608b9b49b8a40 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Sun, 12 Feb 2023 16:23:55 +0100 Subject: [PATCH] migration error handling --- src/utils/storage.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/storage.ts b/src/utils/storage.ts index b7bed37f..349a8707 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -44,9 +44,16 @@ export async function initializeStores() { // Migrate over each version let mostRecentData = data; - for (const version of relevantVersions) { - if (version.migrate) - mostRecentData = await version.migrate(mostRecentData); + try { + for (const version of relevantVersions) { + if (version.migrate) + mostRecentData = await version.migrate(mostRecentData); + } + } catch (err) { + console.error(`FAILED TO MIGRATE STORE ${internal.key}`, err); + // reset store to lastest version create + mostRecentData = + relevantVersions[relevantVersions.length - 1].create?.() ?? {}; } store.save(mostRecentData);