From 3f8cbcd18f47fcae8c0d8060fd8c245c025784c0 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Mon, 29 Jan 2024 10:34:16 -0800 Subject: [PATCH] Catch transaction.done errors (#7984) --- .changeset/few-drinks-kiss.md | 5 +++++ packages/app/src/indexeddb.ts | 9 +++++---- 2 files changed, 10 insertions(+), 4 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..7cd1c29eaa5 100644 --- a/packages/app/src/indexeddb.ts +++ b/packages/app/src/indexeddb.ts @@ -69,10 +69,11 @@ export async function readHeartbeatsFromIndexedDB( ): Promise { try { const db = await getDbPromise(); - const result = await db - .transaction(STORE_NAME) - .objectStore(STORE_NAME) - .get(computeKey(app)); + 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) {