aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/background.js
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-04-10 04:56:59 +0800
committerGitHub <noreply@github.com>2018-04-10 04:56:59 +0800
commitdf1f891585dc41a7d725d592902a84e432e66dc4 (patch)
treee450c931e8d6d4a1277fd57e330fa8882d7cc93f /app/scripts/background.js
parent931ce120737210cbbf6736b454580ac0610f527a (diff)
parent305f5f0034f347ee3eacbc4e6ef41817c1de9ab2 (diff)
downloadtangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.tar
tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.tar.gz
tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.tar.bz2
tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.tar.lz
tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.tar.xz
tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.tar.zst
tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.zip
Merge branch 'master' into i3621-LogoPerformance
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r--app/scripts/background.js54
1 files changed, 50 insertions, 4 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 3ad0a7863..5878cd2e8 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -20,6 +20,7 @@ const reportFailedTxToSentry = require('./lib/reportFailedTxToSentry')
const setupMetamaskMeshMetrics = require('./lib/setupMetamaskMeshMetrics')
const EdgeEncryptor = require('./edge-encryptor')
const getFirstPreferredLangCode = require('./lib/get-first-preferred-lang-code')
+const getObjStructure = require('./lib/getObjStructure')
const STORAGE_KEY = 'metamask-config'
const METAMASK_DEBUG = process.env.METAMASK_DEBUG
@@ -77,6 +78,38 @@ async function loadStateFromPersistence () {
diskStore.getState() ||
migrator.generateInitialState(firstTimeState)
+ // check if somehow state is empty
+ // this should never happen but new error reporting suggests that it has
+ // for a small number of users
+ // https://github.com/metamask/metamask-extension/issues/3919
+ if (versionedData && !versionedData.data) {
+ // try to recover from diskStore incase only localStore is bad
+ const diskStoreState = diskStore.getState()
+ if (diskStoreState && diskStoreState.data) {
+ // we were able to recover (though it might be old)
+ versionedData = diskStoreState
+ const vaultStructure = getObjStructure(versionedData)
+ raven.captureMessage('MetaMask - Empty vault found - recovered from diskStore', {
+ // "extra" key is required by Sentry
+ extra: { vaultStructure },
+ })
+ } else {
+ // unable to recover, clear state
+ versionedData = migrator.generateInitialState(firstTimeState)
+ raven.captureMessage('MetaMask - Empty vault found - unable to recover')
+ }
+ }
+
+ // report migration errors to sentry
+ migrator.on('error', (err) => {
+ // get vault structure without secrets
+ const vaultStructure = getObjStructure(versionedData)
+ raven.captureException(err, {
+ // "extra" key is required by Sentry
+ extra: { vaultStructure },
+ })
+ })
+
// migrate data
versionedData = await migrator.migrateData(versionedData)
if (!versionedData) {
@@ -84,7 +117,14 @@ async function loadStateFromPersistence () {
}
// write to disk
- if (localStore.isSupported) localStore.set(versionedData)
+ if (localStore.isSupported) {
+ localStore.set(versionedData)
+ } else {
+ // throw in setTimeout so as to not block boot
+ setTimeout(() => {
+ throw new Error('MetaMask - Localstore not supported')
+ })
+ }
// return just the data
return versionedData.data
@@ -122,9 +162,9 @@ function setupController (initState, initLangCode) {
asStream(controller.store),
debounce(1000),
storeTransform(versionifyData),
- storeTransform(syncDataWithExtension),
+ storeTransform(persistData),
(error) => {
- log.error('pump hit error', error)
+ log.error('MetaMask - Persistence pipeline failed', error)
}
)
@@ -133,7 +173,13 @@ function setupController (initState, initLangCode) {
return versionedData
}
- function syncDataWithExtension(state) {
+ function persistData(state) {
+ if (!state) {
+ throw new Error('MetaMask - updated state is missing', state)
+ }
+ if (!state.data) {
+ throw new Error('MetaMask - updated state does not have data', state)
+ }
if (localStore.isSupported) {
localStore.set(state)
.catch((err) => {