diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-04-07 04:18:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-07 04:18:48 +0800 |
commit | 2511a9e634234135862259510a38b69308c2b81b (patch) | |
tree | eda940e6d4349b556e40be25ff30dbae3cc4d7de /app | |
parent | 2b787f2833d4f4cfda74ca22d3d340f0f924c94e (diff) | |
parent | f9a6feb26369048d63cc3794f4f94db4c89ed287 (diff) | |
download | tangerine-wallet-browser-2511a9e634234135862259510a38b69308c2b81b.tar tangerine-wallet-browser-2511a9e634234135862259510a38b69308c2b81b.tar.gz tangerine-wallet-browser-2511a9e634234135862259510a38b69308c2b81b.tar.bz2 tangerine-wallet-browser-2511a9e634234135862259510a38b69308c2b81b.tar.lz tangerine-wallet-browser-2511a9e634234135862259510a38b69308c2b81b.tar.xz tangerine-wallet-browser-2511a9e634234135862259510a38b69308c2b81b.tar.zst tangerine-wallet-browser-2511a9e634234135862259510a38b69308c2b81b.zip |
Merge pull request #3922 from MetaMask/empty-vault-fix
Empty vault - attempt recovery
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/background.js | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index ec586f642..5878cd2e8 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -78,6 +78,28 @@ 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 @@ -140,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) } ) @@ -151,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) => { |