Skip to content

Reject IndexedDB init instead of throwing when the upgrade fails - #661

Open
pkuczynski wants to merge 1 commit into
mixpanel:masterfrom
pkuczynski:fix/idb-upgrade-missing-result
Open

pkuczynski wants to merge 1 commit into
mixpanel:masterfrom
pkuczynski:fix/idb-upgrade-missing-result

Conversation

@pkuczynski

Copy link
Copy Markdown
Contributor

Fixes #611.

onupgradeneeded reads the database from ev.target.result. On WebKit that is sometimes undefined, and the handler throws TypeError: undefined is not an object (evaluating 'db.objectStoreNames'). The throw escapes as an uncaught exception, so init() callers never see a rejection.

This change:

  • reads the database from openRequest.result, with ev.target.result as the fallback;
  • rejects the open promise if there is no database or creating a store throws;
  • aborts the version change transaction in that case.

Tests in tests/unit/indexed-db.js:

  • the event has no result but the request has one: init resolves and stores work;
  • neither has one: init rejects, no uncaught exception;
  • createObjectStore throws: init rejects, no uncaught exception.

The three new tests fail without the fix. npm run lint and the full unit suite pass.

Read the database from the open request, and fall back to the event
target. If neither has one, or creating a store throws, reject the open
promise and abort the version change transaction. Before, the error
escaped onupgradeneeded as an uncaught exception on WebKit.

Fixes mixpanel#611
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled IndexedDB upgrade error on Safari/WebKit when event.target.result is undefined

1 participant