From 2b880dd4e060f8f7f95afe9ff2a3e2e6d540c922 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 5 Apr 2018 13:15:08 -0700 Subject: migrations - report migrations errors to sentry with vault structure --- app/scripts/background.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'app/scripts/background.js') diff --git a/app/scripts/background.js b/app/scripts/background.js index 3ad0a7863..ec586f642 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,16 @@ async function loadStateFromPersistence () { diskStore.getState() || migrator.generateInitialState(firstTimeState) + // 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 +95,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 -- cgit v1.2.3 From 0685381fdcd3ab8cebc76bf73e9678deaf5d15f8 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 6 Apr 2018 12:05:24 -0700 Subject: metamask - attempt recovery from empty vault --- app/scripts/background.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'app/scripts/background.js') diff --git a/app/scripts/background.js b/app/scripts/background.js index ec586f642..a4d95289b 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 -- cgit v1.2.3 From 6f4dbd6d4a27888ccff88d336ae4340cb69c90e7 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 6 Apr 2018 12:08:51 -0700 Subject: metamask - never persist if state is missing data --- app/scripts/background.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/scripts/background.js') diff --git a/app/scripts/background.js b/app/scripts/background.js index a4d95289b..837fd7133 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -162,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) } ) @@ -173,7 +173,10 @@ function setupController (initState, initLangCode) { return versionedData } - function syncDataWithExtension(state) { + function persistData(state) { + if (!state.data) { + throw new Error('MetaMask - updated state is missing data', state) + } if (localStore.isSupported) { localStore.set(state) .catch((err) => { -- cgit v1.2.3 From f9a6feb26369048d63cc3794f4f94db4c89ed287 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 6 Apr 2018 12:10:39 -0700 Subject: metamask - never persist if state is missing --- app/scripts/background.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/scripts/background.js') diff --git a/app/scripts/background.js b/app/scripts/background.js index 837fd7133..5878cd2e8 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -174,8 +174,11 @@ function setupController (initState, initLangCode) { } function persistData(state) { + if (!state) { + throw new Error('MetaMask - updated state is missing', state) + } if (!state.data) { - throw new Error('MetaMask - updated state is missing data', state) + throw new Error('MetaMask - updated state does not have data', state) } if (localStore.isSupported) { localStore.set(state) -- cgit v1.2.3