Merge pull request #4146 from MetaMask/sentry-error-like2

sentry - add helper to fully rewrite all error messages
feature/default_network_editable
kumavis 7 years ago committed by GitHub
commit 76c8cb3d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      app/scripts/lib/setupRaven.js

@ -25,7 +25,7 @@ function setupRaven(opts) {
const report = opts.data const report = opts.data
try { try {
// handle error-like non-error exceptions // handle error-like non-error exceptions
nonErrorException(report) rewriteErrorLikeExceptions(report)
// simplify certain complex error messages (e.g. Ethjs) // simplify certain complex error messages (e.g. Ethjs)
simplifyErrorMessages(report) simplifyErrorMessages(report)
// modify report urls // modify report urls
@ -42,27 +42,35 @@ function setupRaven(opts) {
return Raven return Raven
} }
function nonErrorException(report) { function rewriteErrorLikeExceptions(report) {
// handle errors that lost their error-ness in serialization // handle errors that lost their error-ness in serialization (e.g. dnode)
if (report.message.includes('Non-Error exception captured with keys: message')) { rewriteErrorMessages(report, (errorMessage) => {
if (!(report.extra && report.extra.__serialized__)) return if (!errorMessage.includes('Non-Error exception captured with keys:')) return errorMessage
report.message = `Non-Error Exception: ${report.extra.__serialized__.message}` if (!(report.extra && report.extra.__serialized__ && report.extra.__serialized__.message)) return errorMessage
} return `Non-Error Exception: ${report.extra.__serialized__.message}`
})
} }
function simplifyErrorMessages(report) { function simplifyErrorMessages(report) {
rewriteErrorMessages(report, (errorMessage) => {
// simplify ethjs error messages
errorMessage = extractEthjsErrorMessage(errorMessage)
// simplify 'Transaction Failed: known transaction'
if (errorMessage.indexOf('Transaction Failed: known transaction') === 0) {
// cut the hash from the error message
errorMessage = 'Transaction Failed: known transaction'
}
return errorMessage
})
}
function rewriteErrorMessages(report, rewriteFn) {
// rewrite top level message
report.message = rewriteFn(report.message)
// rewrite each exception message
if (report.exception && report.exception.values) { if (report.exception && report.exception.values) {
report.exception.values.forEach(item => { report.exception.values.forEach(item => {
let errorMessage = item.value item.value = rewriteFn(item.value)
// simplify ethjs error messages
errorMessage = extractEthjsErrorMessage(errorMessage)
// simplify 'Transaction Failed: known transaction'
if (errorMessage.indexOf('Transaction Failed: known transaction') === 0) {
// cut the hash from the error message
errorMessage = 'Transaction Failed: known transaction'
}
// finalize
item.value = errorMessage
}) })
} }
} }

Loading…
Cancel
Save