From 2d59567238b37cdca24e4cf61700d18dd2fb3d40 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Fri, 26 Jan 2024 15:01:42 -0800 Subject: [PATCH 1/2] Catch transaction.done errors --- .changeset/few-drinks-kiss.md | 5 +++++ packages/app/src/indexeddb.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/few-drinks-kiss.md diff --git a/.changeset/few-drinks-kiss.md b/.changeset/few-drinks-kiss.md new file mode 100644 index 00000000000..fb763adc6a9 --- /dev/null +++ b/.changeset/few-drinks-kiss.md @@ -0,0 +1,5 @@ +--- +'@firebase/app': patch +--- + +Catch `transaction.done` errors in `readHeartbeatsFromIndexedDB` and log them as a warning, because platform logging errors should never throw or block user app functionality. diff --git a/packages/app/src/indexeddb.ts b/packages/app/src/indexeddb.ts index 07f18d807b6..972f0c9ec01 100644 --- a/packages/app/src/indexeddb.ts +++ b/packages/app/src/indexeddb.ts @@ -69,10 +69,13 @@ export async function readHeartbeatsFromIndexedDB( ): Promise { try { const db = await getDbPromise(); - const result = await db - .transaction(STORE_NAME) + const tx = db.transaction(STORE_NAME); + const result = await tx .objectStore(STORE_NAME) .get(computeKey(app)); + // We already have the value but tx.done can throw, + // so we need to await it here to catch errors + await tx.done; return result; } catch (e) { if (e instanceof FirebaseError) { From 8ddc7e3aabce3ce8545c68f9e99348737ed9615e Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Fri, 26 Jan 2024 15:04:54 -0800 Subject: [PATCH 2/2] format --- packages/app/src/indexeddb.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/app/src/indexeddb.ts b/packages/app/src/indexeddb.ts index 972f0c9ec01..7cd1c29eaa5 100644 --- a/packages/app/src/indexeddb.ts +++ b/packages/app/src/indexeddb.ts @@ -70,9 +70,7 @@ export async function readHeartbeatsFromIndexedDB( try { const db = await getDbPromise(); const tx = db.transaction(STORE_NAME); - const result = await tx - .objectStore(STORE_NAME) - .get(computeKey(app)); + const result = await tx.objectStore(STORE_NAME).get(computeKey(app)); // We already have the value but tx.done can throw, // so we need to await it here to catch errors await tx.done;