From 59918fdee5c4785bd00741f660b931464910169a Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 24 Jul 2016 13:26:34 -0400 Subject: [PATCH] Handle empty/corrupted IDB --- assets/javascripts/app/db.coffee | 21 ++++++++++++------- .../javascripts/templates/error_tmpl.coffee | 9 +++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/assets/javascripts/app/db.coffee b/assets/javascripts/app/db.coffee index 9afd5ced..ce08a704 100644 --- a/assets/javascripts/app/db.coffee +++ b/assets/javascripts/app/db.coffee @@ -22,17 +22,24 @@ class app.DB return onOpenSuccess: (event) => - try - db = event.target.result - unless @checkedBuggyIDB - @checkedBuggyIDB = true - @idbTransaction(db, stores: $.makeArray(db.objectStoreNames)[0..1], mode: 'readwrite').abort() # https://bugs.webkit.org/show_bug.cgi?id=136937 - catch + db = event.target.result + + if db.objectStoreNames.length is 0 try db.close() - @reason = 'apple' + @reason = 'empty' @onOpenError() return + unless @checkedBuggyIDB + @checkedBuggyIDB = true + try + @idbTransaction(db, stores: $.makeArray(db.objectStoreNames)[0..1], mode: 'readwrite').abort() # https://bugs.webkit.org/show_bug.cgi?id=136937 + catch + try db.close() + @reason = 'apple' + @onOpenError() + return + @runCallbacks(db) @open = false db.close() diff --git a/assets/javascripts/templates/error_tmpl.coffee b/assets/javascripts/templates/error_tmpl.coffee index f5a33413..e2caf83d 100644 --- a/assets/javascripts/templates/error_tmpl.coffee +++ b/assets/javascripts/templates/error_tmpl.coffee @@ -25,10 +25,13 @@ app.templates.bootError = -> app.templates.offlineError = (reason) -> reason = switch reason when 'not_supported' - """ Unfortunately your browser either doesn't support it or does not make it available. """ + """ Unfortunately your browser either doesn't support IndexedDB or does not make it available. """ when 'cant_open' - """ Although your browser appears to support it, DevDocs couldn't open the database.
- This could be because you're browsing in private mode and have disallowed offline storage on the domain. """ + """ Although your browser supports IndexedDB, DevDocs couldn't open the database.
+ This could be because you're browsing in private mode or have disallowed offline storage on the domain. """ + when 'empty' + """ Although your browser supports IndexedDB, DevDocs couldn't properly set up the database.
+ This could be because the database is corrupted. Try resetting the app. """ when 'apple' """ Unfortunately Safari's implementation of IndexedDB is badly broken.
This message will automatically go away when Apple fix their code. """