Skip to content

Commit 32cb0e1

Browse files
author
Michael Lehenbauer
authored
Make IOS_INDEXEDDB_BUG1 error more prominent when it happens (so it shows up in the error surfaced repeatedly by the AsyncQueue). (#1896)
1 parent 7a52f75 commit 32cb0e1

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

packages/firestore/src/local/simple_db.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,9 @@ export class SimpleDbTransaction {
378378
}
379379
};
380380
this.transaction.onerror = (event: Event) => {
381-
const error = (event.target as IDBRequest).error!;
382-
checkForAndReportiOSError(error);
381+
const error = checkForAndReportiOSError(
382+
(event.target as IDBRequest).error!
383+
);
383384
this.completionDeferred.reject(error);
384385
};
385386
}
@@ -599,8 +600,9 @@ export class SimpleDbStore<
599600
const cursorRequest = this.cursor({});
600601
return new PersistencePromise((resolve, reject) => {
601602
cursorRequest.onerror = (event: Event) => {
602-
const error = (event.target as IDBRequest).error!;
603-
checkForAndReportiOSError(error);
603+
const error = checkForAndReportiOSError(
604+
(event.target as IDBRequest).error!
605+
);
604606
reject(error);
605607
};
606608
cursorRequest.onsuccess = (event: Event) => {
@@ -715,35 +717,39 @@ function wrapRequest<R>(request: IDBRequest): PersistencePromise<R> {
715717
};
716718

717719
request.onerror = (event: Event) => {
718-
const error = (event.target as IDBRequest).error!;
719-
checkForAndReportiOSError(error);
720+
const error = checkForAndReportiOSError(
721+
(event.target as IDBRequest).error!
722+
);
720723
reject(error);
721724
};
722725
});
723726
}
724727

725728
// Guard so we only report the error once.
726729
let reportedIOSError = false;
727-
function checkForAndReportiOSError(error: DOMException): void {
728-
if (reportedIOSError) {
729-
return;
730-
}
730+
function checkForAndReportiOSError(error: DOMException): Error {
731731
const iOSVersion = SimpleDb.getIOSVersion(getUA());
732732
if (iOSVersion >= 12.2 && iOSVersion < 13) {
733733
const IOS_ERROR =
734734
'An internal error was encountered in the Indexed Database server';
735735
if (error.message.indexOf(IOS_ERROR) >= 0) {
736-
reportedIOSError = true;
737-
// Throw a global exception outside of this promise chain, for the user to
738-
// potentially catch.
739-
setTimeout(() => {
740-
throw new FirestoreError(
741-
'internal',
742-
`IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${IOS_ERROR}'. This is likely ` +
743-
`due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 ` +
744-
`for details and a potential workaround.`
745-
);
746-
}, 0);
736+
// Wrap error in a more descriptive one.
737+
const newError = new FirestoreError(
738+
'internal',
739+
`IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${IOS_ERROR}'. This is likely ` +
740+
`due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 ` +
741+
`for details and a potential workaround.`
742+
);
743+
if (!reportedIOSError) {
744+
reportedIOSError = true;
745+
// Throw a global exception outside of this promise chain, for the user to
746+
// potentially catch.
747+
setTimeout(() => {
748+
throw newError;
749+
}, 0);
750+
}
751+
return newError;
747752
}
748753
}
754+
return error;
749755
}

0 commit comments

Comments
 (0)