From fca2cbc8ef8e0d8434fd8c437497a7a0792e2caf Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Feb 2018 10:37:53 -0800 Subject: [PATCH 1/3] sentry - clean - move setupRaven to lib --- app/scripts/background.js | 2 +- app/scripts/{ => lib}/setupRaven.js | 2 +- app/scripts/popup.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename app/scripts/{ => lib}/setupRaven.js (92%) diff --git a/app/scripts/background.js b/app/scripts/background.js index 476d073d1..0da079eb6 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -13,7 +13,7 @@ const PortStream = require('./lib/port-stream.js') const NotificationManager = require('./lib/notification-manager.js') const MetamaskController = require('./metamask-controller') const firstTimeState = require('./first-time-state') -const setupRaven = require('./setupRaven') +const setupRaven = require('./lib/setupRaven') const setupMetamaskMeshMetrics = require('./lib/setupMetamaskMeshMetrics') const STORAGE_KEY = 'metamask-config' diff --git a/app/scripts/setupRaven.js b/app/scripts/lib/setupRaven.js similarity index 92% rename from app/scripts/setupRaven.js rename to app/scripts/lib/setupRaven.js index 7beffeff9..42e48cb90 100644 --- a/app/scripts/setupRaven.js +++ b/app/scripts/lib/setupRaven.js @@ -1,4 +1,4 @@ -const Raven = require('./vendor/raven.min.js') +const Raven = require('../vendor/raven.min.js') const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' const PROD = 'https://3567c198f8a8412082d32655da2961d0@sentry.io/273505' const DEV = 'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496' diff --git a/app/scripts/popup.js b/app/scripts/popup.js index 53ab00e00..11d50ee87 100644 --- a/app/scripts/popup.js +++ b/app/scripts/popup.js @@ -8,7 +8,7 @@ const extension = require('extensionizer') const ExtensionPlatform = require('./platforms/extension') const NotificationManager = require('./lib/notification-manager') const notificationManager = new NotificationManager() -const setupRaven = require('./setupRaven') +const setupRaven = require('./lib/setupRaven') // create platform global global.platform = new ExtensionPlatform() From 8e5bcf89359edb70b5d6847a4848c222aa283066 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Feb 2018 10:53:54 -0800 Subject: [PATCH 2/3] sentry - failed tx - improve ethjs-rpc error formating --- app/scripts/background.js | 8 ++--- app/scripts/lib/reportFailedTxToSentry.js | 38 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 app/scripts/lib/reportFailedTxToSentry.js diff --git a/app/scripts/background.js b/app/scripts/background.js index 0da079eb6..4487ff318 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -14,8 +14,10 @@ const NotificationManager = require('./lib/notification-manager.js') const MetamaskController = require('./metamask-controller') const firstTimeState = require('./first-time-state') const setupRaven = require('./lib/setupRaven') +const reportFailedTxToSentry = require('./lib/reportFailedTxToSentry') const setupMetamaskMeshMetrics = require('./lib/setupMetamaskMeshMetrics') + const STORAGE_KEY = 'metamask-config' const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' @@ -86,11 +88,7 @@ function setupController (initState) { controller.txController.on(`tx:status-update`, (txId, status) => { if (status !== 'failed') return const txMeta = controller.txController.txStateManager.getTx(txId) - const errorMessage = `Transaction Failed: ${txMeta.err.message}` - raven.captureMessage(errorMessage, { - // "extra" key is required by Sentry - extra: txMeta, - }) + reportFailedTxToSentry({ raven, txMeta }) }) // setup state persistence diff --git a/app/scripts/lib/reportFailedTxToSentry.js b/app/scripts/lib/reportFailedTxToSentry.js new file mode 100644 index 000000000..67b0acf43 --- /dev/null +++ b/app/scripts/lib/reportFailedTxToSentry.js @@ -0,0 +1,38 @@ +const ethJsRpcSlug = 'Error: [ethjs-rpc] rpc error with payload ' +const errorLabelPrefix = 'Error: ' + +module.exports = reportFailedTxToSentry + +// +// utility for formatting failed transaction messages +// for sending to sentry +// + +function reportFailedTxToSentry({ raven, txMeta }) { + const errorMessage = extractErrorMessage(txMeta.err.message) + raven.captureMessage(errorMessage, { + // "extra" key is required by Sentry + extra: txMeta, + }) +} + +// +// ethjs-rpc provides overly verbose error messages +// if we detect this type of message, we extract the important part +// Below is an example input and output +// +// Error: [ethjs-rpc] rpc error with payload {"id":3947817945380,"jsonrpc":"2.0","params":["0xf8eb8208708477359400830398539406012c8cf97bead5deae237070f9587f8e7a266d80b8843d7d3f5a0000000000000000000000000000000000000000000000000000000000081d1a000000000000000000000000000000000000000000000000001ff973cafa800000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000003f48025a04c32a9b630e0d9e7ff361562d850c86b7a884908135956a7e4a336fa0300d19ca06830776423f25218e8d19b267161db526e66895567147015b1f3fc47aef9a3c7"],"method":"eth_sendRawTransaction"} Error: replacement transaction underpriced +// +// "Transaction Failed: replacement transaction underpriced" +// + +function extractErrorMessage(errorMessage) { + const isEthjsRpcError = errorMessage.includes(ethJsRpcSlug) + if (isEthjsRpcError) { + const payloadAndError = errorMessage.slice(ethJsRpcSlug.length) + const originalError = payloadAndError.slice(payloadAndError.indexOf(errorLabelPrefix) + errorLabelPrefix.length) + return `Transaction Failed: ${originalError}` + } else { + return `Transaction Failed: ${errorMessage}` + } +} From c3bd27c9657d5e0236e2960dedd108ca5e2bb0ec Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Feb 2018 10:57:54 -0800 Subject: [PATCH 3/3] sentry - extractErrorMessage - fix comment formatting --- app/scripts/lib/reportFailedTxToSentry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/lib/reportFailedTxToSentry.js b/app/scripts/lib/reportFailedTxToSentry.js index 67b0acf43..ee73f6845 100644 --- a/app/scripts/lib/reportFailedTxToSentry.js +++ b/app/scripts/lib/reportFailedTxToSentry.js @@ -23,7 +23,7 @@ function reportFailedTxToSentry({ raven, txMeta }) { // // Error: [ethjs-rpc] rpc error with payload {"id":3947817945380,"jsonrpc":"2.0","params":["0xf8eb8208708477359400830398539406012c8cf97bead5deae237070f9587f8e7a266d80b8843d7d3f5a0000000000000000000000000000000000000000000000000000000000081d1a000000000000000000000000000000000000000000000000001ff973cafa800000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000003f48025a04c32a9b630e0d9e7ff361562d850c86b7a884908135956a7e4a336fa0300d19ca06830776423f25218e8d19b267161db526e66895567147015b1f3fc47aef9a3c7"],"method":"eth_sendRawTransaction"} Error: replacement transaction underpriced // -// "Transaction Failed: replacement transaction underpriced" +// Transaction Failed: replacement transaction underpriced // function extractErrorMessage(errorMessage) {