{"action":"created","issue":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4977","repository_url":"https://api.github.com/repos/pouchdb/pouchdb","labels_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4977/labels{/name}","comments_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4977/comments","events_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4977/events","html_url":"https://github.com/pouchdb/pouchdb/issues/4977","id":141202962,"number":4977,"title":"Throw error instead of just console.log","user":{"login":"Heshyo","id":6860101,"avatar_url":"https://avatars.githubusercontent.com/u/6860101?v=3","gravatar_id":"","url":"https://api.github.com/users/Heshyo","html_url":"https://github.com/Heshyo","followers_url":"https://api.github.com/users/Heshyo/followers","following_url":"https://api.github.com/users/Heshyo/following{/other_user}","gists_url":"https://api.github.com/users/Heshyo/gists{/gist_id}","starred_url":"https://api.github.com/users/Heshyo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Heshyo/subscriptions","organizations_url":"https://api.github.com/users/Heshyo/orgs","repos_url":"https://api.github.com/users/Heshyo/repos","events_url":"https://api.github.com/users/Heshyo/events{/privacy}","received_events_url":"https://api.github.com/users/Heshyo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-16T08:12:18Z","updated_at":"2016-05-03T01:23:54Z","closed_at":null,"body":"If the user clears the cache of the browser then obviously he'll lose everything stored on Pouch. The issue is that I'd like to be able to detect such scenario. I've seen a few places where we get an error which is not accessible.\r\n\r\n- First error:\r\n\r\n```\r\n    idb.onabort = function (e) {\r\n      console.error('Database has a global failure', e.target.error);\r\n      idb.close();\r\n      cachedDBs[\"delete\"](dbName);\r\n    };\r\n```\r\nThis displays the error `Database has a global failure DOMException: Connection is closing.`.\r\nCouldn't we throw an error at the end, eg `throw new Error(\"Database has a global failure \" +  e.target.error.message);`, so that we'd be able to access it in `window.onerror`?\r\n\r\nI've tested throwing an error and I can see it in `window.onerror`, but I don't know if there are other things to consider.\r\n\r\n\r\n- Second error:\r\n\r\n```\r\nfunction openTransactionSafely(idb, stores, mode) {\r\n  try {\r\n    return {\r\n      txn: idb.transaction(stores, mode)\r\n    };\r\n  } catch (err) {\r\n    return {\r\n      error: err\r\n    };\r\n  }\r\n}\r\n```\r\nThe browser logs the error `Uncaught (in promise) DOMException: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.`. Could we have something like\r\n```\r\nvar txn = idb.transaction(stores, mode);\r\ntxn.onerror = function() {\r\n    throw new Error(\"Database has a global failure.\");\r\n};\r\nreturn {\r\n  txn: txn\r\n};\r\n\r\n```\r\nI've tested that code and I can see it in `window.onerror`, but again I don't know if there are other things to consider. Note that if in some parts of the code we don't want that behavior, we can always override the onerror (I've seen the `onerror` used once: `tx.onerror = idbError(callback);`, and as it's set afterwards, it would override the `throw`).\r\n"},"comment":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/comments/216411091","html_url":"https://github.com/pouchdb/pouchdb/issues/4977#issuecomment-216411091","issue_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4977","id":216411091,"user":{"login":"nolanlawson","id":283842,"avatar_url":"https://avatars.githubusercontent.com/u/283842?v=3","gravatar_id":"","url":"https://api.github.com/users/nolanlawson","html_url":"https://github.com/nolanlawson","followers_url":"https://api.github.com/users/nolanlawson/followers","following_url":"https://api.github.com/users/nolanlawson/following{/other_user}","gists_url":"https://api.github.com/users/nolanlawson/gists{/gist_id}","starred_url":"https://api.github.com/users/nolanlawson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nolanlawson/subscriptions","organizations_url":"https://api.github.com/users/nolanlawson/orgs","repos_url":"https://api.github.com/users/nolanlawson/repos","events_url":"https://api.github.com/users/nolanlawson/events{/privacy}","received_events_url":"https://api.github.com/users/nolanlawson/received_events","type":"User","site_admin":false},"created_at":"2016-05-03T01:23:54Z","updated_at":"2016-05-03T01:23:54Z","body":"I commented in https://github.com/pouchdb/pouchdb/pull/5045#issuecomment-210861558 about this; in general I think it would be better to be consistent about our `onabort` usage rather than try to catch all `onaborts` in one place. This is also a nasty bit of code, because it's almost impossible to actually consistently reproduce `onabort` errors without some fancy multi-tab tests (e.g. closing on IDB in one tab while using it in another one)."}}