aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/background.js
diff options
context:
space:
mode:
authorThomas <tmashuang@gmail.com>2018-04-11 23:35:31 +0800
committerThomas <tmashuang@gmail.com>2018-04-11 23:35:31 +0800
commitf82c51c2c4782f54fb1d690f2dc1c309fafefe65 (patch)
tree84e5d2a1b989459f3dbb6f74e1921b4b83f705a0 /app/scripts/background.js
parent30474ccd35d5d7f30ffb8dff0acc8fbc77f44731 (diff)
parent29dab1e9e00c1c1e6ad834026df51b2839d3171d (diff)
downloadtangerine-wallet-browser-f82c51c2c4782f54fb1d690f2dc1c309fafefe65.tar
tangerine-wallet-browser-f82c51c2c4782f54fb1d690f2dc1c309fafefe65.tar.gz
tangerine-wallet-browser-f82c51c2c4782f54fb1d690f2dc1c309fafefe65.tar.bz2
tangerine-wallet-browser-f82c51c2c4782f54fb1d690f2dc1c309fafefe65.tar.lz
tangerine-wallet-browser-f82c51c2c4782f54fb1d690f2dc1c309fafefe65.tar.xz
tangerine-wallet-browser-f82c51c2c4782f54fb1d690f2dc1c309fafefe65.tar.zst
tangerine-wallet-browser-f82c51c2c4782f54fb1d690f2dc1c309fafefe65.zip
Merge branch 'master' into testing
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r--app/scripts/background.js58
1 files changed, 52 insertions, 6 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 7782fc41e..5878cd2e8 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -20,9 +20,10 @@ 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 = 'GULP_METAMASK_DEBUG'
+const METAMASK_DEBUG = process.env.METAMASK_DEBUG
window.log = log
log.setDefaultLevel(METAMASK_DEBUG ? 'debug' : 'warn')
@@ -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
@@ -94,7 +134,7 @@ function setupController (initState, initLangCode) {
//
// MetaMask Controller
//
-
+
const controller = new MetamaskController({
// User confirmation callbacks:
showUnconfirmedMessage: triggerUi,
@@ -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) => {