cleanErrorStack moved to separate library module

more errors traces cleaned up
feature/default_network_editable
Anton 7 years ago
parent 1d23a5c81b
commit 71a6e97327
  1. 16
      app/scripts/controllers/transactions/index.js
  2. 24
      app/scripts/lib/cleanErrorStack.js
  3. 15
      app/scripts/metamask-controller.js

@ -8,6 +8,7 @@ const TxGasUtil = require('./tx-gas-utils')
const PendingTransactionTracker = require('./pending-tx-tracker')
const NonceTracker = require('./nonce-tracker')
const txUtils = require('./lib/util')
const cleanErrorStack = require('../../lib/cleanErrorStack')
const log = require('loglevel')
/**
@ -111,15 +112,6 @@ class TransactionController extends EventEmitter {
this.txStateManager.wipeTransactions(address)
}
/**
Returns error without stack trace for better UI display
@param {Error} err - error which stack will be cleaned
*/
cleanErrorStack(err){
err.stack = err.name + ': ' + err.message
return err
}
/**
add a new unapproved transaction to the pipeline
@ -140,11 +132,11 @@ class TransactionController extends EventEmitter {
case 'submitted':
return resolve(finishedTxMeta.hash)
case 'rejected':
return reject(this.cleanErrorStack(new Error('MetaMask Tx Signature: User denied transaction signature.')))
return reject(cleanErrorStack(new Error('MetaMask Tx Signature: User denied transaction signature.')))
case 'failed':
return reject(this.cleanErrorStack(new Error(finishedTxMeta.err.message)))
return reject(cleanErrorStack(new Error(finishedTxMeta.err.message)))
default:
return reject(this.cleanErrorStack(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`)))
return reject(cleanErrorStack(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`)))
}
})
})

@ -0,0 +1,24 @@
/**
* Returns error without stack trace for better UI display
* @param {Error} err - error
* @returns {Error} Error with clean stack trace.
*/
function cleanErrorStack(err){
var name = err.name
name = (name === undefined) ? 'Error' : String(name)
var msg = err.message
msg = (msg === undefined) ? '' : String(msg)
if (name === '') {
err.stack = err.message
} else if (msg === '') {
err.stack = err.name
} else {
err.stack = err.name + ': ' + err.message
}
return err
}
module.exports = cleanErrorStack

@ -45,6 +45,7 @@ const BN = require('ethereumjs-util').BN
const GWEI_BN = new BN('1000000000')
const percentile = require('percentile')
const seedPhraseVerifier = require('./lib/seed-phrase-verifier')
const cleanErrorStack = require('./lib/cleanErrorStack')
const log = require('loglevel')
module.exports = class MetamaskController extends EventEmitter {
@ -637,9 +638,9 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed':
return cb(null, data.rawSig)
case 'rejected':
return cb(new Error('MetaMask Message Signature: User denied message signature.'))
return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
default:
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
}
})
}
@ -697,7 +698,7 @@ module.exports = class MetamaskController extends EventEmitter {
*/
newUnsignedPersonalMessage (msgParams, cb) {
if (!msgParams.from) {
return cb(new Error('MetaMask Message Signature: from field is required.'))
return cb(cleanErrorStack(new Error('MetaMask Message Signature: from field is required.')))
}
const msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
@ -708,9 +709,9 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed':
return cb(null, data.rawSig)
case 'rejected':
return cb(new Error('MetaMask Message Signature: User denied message signature.'))
return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
default:
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
}
})
}
@ -776,9 +777,9 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed':
return cb(null, data.rawSig)
case 'rejected':
return cb(new Error('MetaMask Message Signature: User denied message signature.'))
return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
default:
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
}
})
}

Loading…
Cancel
Save