Skip to content
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

Open Is Still Successful If Upgrade Throws Exception #294

Open
bcwhite-code opened this issue May 26, 2023 · 0 comments
Open

Open Is Still Successful If Upgrade Throws Exception #294

bcwhite-code opened this issue May 26, 2023 · 0 comments

Comments

@bcwhite-code
Copy link

If openDB() causes an upgrade() but that upgrade fails with an exception, it will still call the .then() clause rather than the .catch() clause.

For example, the following code seems okay at first glance:

        openDB(DB_NAME, DB_VERSION, {
            upgrade(db, oldVersion, newVersion, transaction, event) {
                if (oldVersion > 0 && oldVersion != newVersion) {
                    db.deleteObjectStore(DB_TILE_STORE)
                    oldVersion = 0
                }
                if (oldVersion == 0) {
                    db.createObjectStore(DB_TILE_STORE)
                }
            },
        }).then((db) => {
            this.scrimDb = db  // Success
        }).catch((err) => {
            this.scrimDb = null  // Failure
            Toaster.show("Failed to open storage.  Please reload the page.")
        })

However, if for some reason there is no existing DB_TILE_STORE storage then deleteObjectStore() will throw an exception yet the code will still reach the "success" case and set this.scrimDB = db. (This came to my attention because I originally did not have the oldVerision>0 condition and so the delete failed for any new user.)

This is perhaps just an effect of the underlying implementation but it's unexpected nonetheless. I've since put a try/catch around the delete to properly deal with the issue but it would have been easier to track down the problem had the openDB call failed instead of an attempted save later on.

I didn't check if the update was considered successful (i.e. the internal database version number is updated) or not.

BTW, thank you for this adapter! It makes things nice and clean.

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

No branches or pull requests

1 participant