Browse Source

Handle empty/corrupted IDB

Thibaut Courouble 9 years ago
parent
commit
59918fdee5
2 changed files with 20 additions and 10 deletions
  1. 14 7
      assets/javascripts/app/db.coffee
  2. 6 3
      assets/javascripts/templates/error_tmpl.coffee

+ 14 - 7
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()

+ 6 - 3
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.<br>
-          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.<br>
+          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.<br>
+          This could be because the database is corrupted. Try <a href="#" data-behavior="reset">resetting the app</a>. """
     when 'apple'
       """ Unfortunately Safari's implementation of IndexedDB is <a href="https://bugs.webkit.org/show_bug.cgi?id=136937">badly broken</a>.<br>
           This message will automatically go away when Apple fix their code. """