History

Handle empty/corrupted IDB

Thibaut Courouble committed 10 years ago

Commit 59918fd1 parent 4ad18982 files · +20 −10Browse files

Unified · Split

2 files
  1. assets/javascripts/app/db.coffee +14 −7
  2. assets/javascripts/templates/error_tmpl.coffee +6 −3
assets/javascripts/app/db.coffee+14−7
@@ -22,17 +22,24 @@ class app.DB · 21 unmodified lines
2222 return
2323
2424 onOpenSuccess: (event) =>
25− try
26− db = event.target.result
27− unless @checkedBuggyIDB
28− @checkedBuggyIDB = true
29− @idbTransaction(db, stores: $.makeArray(db.objectStoreNames)[0..1], mode: 'readwrite').abort() # https://bugs.webkit.org/show_bug.cgi?id=136937
30− catch
25+ db = event.target.result
26+
27+ if db.objectStoreNames.length is 0
3128 try db.close()
32− @reason = 'apple'
29+ @reason = 'empty'
3330 @onOpenError()
3431 return
3532
33+ unless @checkedBuggyIDB
34+ @checkedBuggyIDB = true
35+ try
36+ @idbTransaction(db, stores: $.makeArray(db.objectStoreNames)[0..1], mode: 'readwrite').abort() # https://bugs.webkit.org/show_bug.cgi?id=136937
37+ catch
38+ try db.close()
39+ @reason = 'apple'
40+ @onOpenError()
41+ return
42+
3643 @runCallbacks(db)
3744 @open = false
3845 db.close()
assets/javascripts/templates/error_tmpl.coffee+6−3
@@ -25,10 +25,13 @@ app.templates.bootError = -> · 24 unmodified lines
2525 app.templates.offlineError = (reason) ->
2626 reason = switch reason
2727 when 'not_supported'
28− """ Unfortunately your browser either doesn't support it or does not make it available. """
28+ """ Unfortunately your browser either doesn't support IndexedDB or does not make it available. """
2929 when 'cant_open'
30− """ Although your browser appears to support it, DevDocs couldn't open the database.<br>
31− This could be because you're browsing in private mode and have disallowed offline storage on the domain. """
30+ """ Although your browser supports IndexedDB, DevDocs couldn't open the database.<br>
31+ This could be because you're browsing in private mode or have disallowed offline storage on the domain. """
32+ when 'empty'
33+ """ Although your browser supports IndexedDB, DevDocs couldn't properly set up the database.<br>
34+ This could be because the database is corrupted. Try <a href="#" data-behavior="reset">resetting the app</a>. """
3235 when 'apple'
3336 """ Unfortunately Safari's implementation of IndexedDB is <a href="https://bugs.webkit.org/show_bug.cgi?id=136937">badly broken</a>.<br>
3437 This message will automatically go away when Apple fix their code. """