Skip to content

Make IOS_INDEXEDDB_BUG1 error more prominent when it happens. #1896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions packages/firestore/src/local/simple_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,9 @@ export class SimpleDbTransaction {
}
};
this.transaction.onerror = (event: Event) => {
const error = (event.target as IDBRequest).error!;
checkForAndReportiOSError(error);
const error = checkForAndReportiOSError(
(event.target as IDBRequest).error!
);
this.completionDeferred.reject(error);
};
}
Expand Down Expand Up @@ -599,8 +600,9 @@ export class SimpleDbStore<
const cursorRequest = this.cursor({});
return new PersistencePromise((resolve, reject) => {
cursorRequest.onerror = (event: Event) => {
const error = (event.target as IDBRequest).error!;
checkForAndReportiOSError(error);
const error = checkForAndReportiOSError(
(event.target as IDBRequest).error!
);
reject(error);
};
cursorRequest.onsuccess = (event: Event) => {
Expand Down Expand Up @@ -715,35 +717,39 @@ function wrapRequest<R>(request: IDBRequest): PersistencePromise<R> {
};

request.onerror = (event: Event) => {
const error = (event.target as IDBRequest).error!;
checkForAndReportiOSError(error);
const error = checkForAndReportiOSError(
(event.target as IDBRequest).error!
);
reject(error);
};
});
}

// Guard so we only report the error once.
let reportedIOSError = false;
function checkForAndReportiOSError(error: DOMException): void {
if (reportedIOSError) {
return;
}
function checkForAndReportiOSError(error: DOMException): Error {
const iOSVersion = SimpleDb.getIOSVersion(getUA());
if (iOSVersion >= 12.2 && iOSVersion < 13) {
const IOS_ERROR =
'An internal error was encountered in the Indexed Database server';
if (error.message.indexOf(IOS_ERROR) >= 0) {
reportedIOSError = true;
// Throw a global exception outside of this promise chain, for the user to
// potentially catch.
setTimeout(() => {
throw new FirestoreError(
'internal',
`IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${IOS_ERROR}'. This is likely ` +
`due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 ` +
`for details and a potential workaround.`
);
}, 0);
// Wrap error in a more descriptive one.
const newError = new FirestoreError(
'internal',
`IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${IOS_ERROR}'. This is likely ` +
`due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 ` +
`for details and a potential workaround.`
);
if (!reportedIOSError) {
reportedIOSError = true;
// Throw a global exception outside of this promise chain, for the user to
// potentially catch.
setTimeout(() => {
throw newError;
}, 0);
}
return newError;
}
}
return error;
}