Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RPC error messages #7173

Merged
merged 4 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/scripts/controllers/provider-approval.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const ObservableStore = require('obs-store')
const SafeEventEmitter = require('safe-event-emitter')
const createAsyncMiddleware = require('json-rpc-engine/src/createAsyncMiddleware')
const { errors: rpcErrors } = require('eth-json-rpc-errors')

/**
* A controller that services user-approved requests for a full Ethereum provider API
Expand Down Expand Up @@ -48,7 +49,7 @@ class ProviderApprovalController extends SafeEventEmitter {
if (approved) {
res.result = [this.preferencesController.getSelectedAddress()]
} else {
throw new Error('User denied account authorization')
throw rpcErrors.eth.userRejectedRequest('User denied account authorization')
}
})
}
Expand Down
7 changes: 4 additions & 3 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const Transaction = require('ethereumjs-tx')
const EthQuery = require('ethjs-query')
const { errors: rpcErrors } = require('eth-json-rpc-errors')
const abi = require('human-standard-token-abi')
const abiDecoder = require('abi-decoder')
abiDecoder.addABI(abi)
Expand Down Expand Up @@ -166,11 +167,11 @@ class TransactionController extends EventEmitter {
case 'submitted':
return resolve(finishedTxMeta.hash)
case 'rejected':
return reject(cleanErrorStack(new Error('MetaMask Tx Signature: User denied transaction signature.')))
return reject(cleanErrorStack(rpcErrors.eth.userRejectedRequest('MetaMask Tx Signature: User denied transaction signature.')))
case 'failed':
return reject(cleanErrorStack(new Error(finishedTxMeta.err.message)))
return reject(cleanErrorStack(rpcErrors.internal(finishedTxMeta.err.message)))
default:
return reject(cleanErrorStack(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`)))
return reject(cleanErrorStack(rpcErrors.internal(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`)))
}
})
})
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/lib/message-manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const EventEmitter = require('events')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const { errors: rpcErrors } = require('eth-json-rpc-errors')
const createId = require('./random-id')

/**
Expand Down Expand Up @@ -82,7 +83,7 @@ module.exports = class MessageManager extends EventEmitter {
case 'signed':
return resolve(data.rawSig)
case 'rejected':
return reject(new Error('MetaMask Message Signature: User denied message signature.'))
return reject(rpcErrors.eth.userRejectedRequest('MetaMask Message Signature: User denied message signature.'))
default:
return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
}
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/lib/personal-message-manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const EventEmitter = require('events')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const { errors: rpcErrors } = require('eth-json-rpc-errors')
const createId = require('./random-id')
const hexRe = /^[0-9A-Fa-f]+$/g
const log = require('loglevel')
Expand Down Expand Up @@ -88,7 +89,7 @@ module.exports = class PersonalMessageManager extends EventEmitter {
case 'signed':
return resolve(data.rawSig)
case 'rejected':
return reject(new Error('MetaMask Message Signature: User denied message signature.'))
return reject(rpcErrors.eth.userRejectedRequest('MetaMask Message Signature: User denied message signature.'))
default:
return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
}
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/lib/typed-message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const EventEmitter = require('events')
const ObservableStore = require('obs-store')
const createId = require('./random-id')
const assert = require('assert')
const { errors: rpcErrors } = require('eth-json-rpc-errors')
const sigUtil = require('eth-sig-util')
const log = require('loglevel')
const jsonschema = require('jsonschema')
Expand Down Expand Up @@ -78,7 +79,7 @@ module.exports = class TypedMessageManager extends EventEmitter {
case 'signed':
return resolve(data.rawSig)
case 'rejected':
return reject(new Error('MetaMask Message Signature: User denied message signature.'))
return reject(rpcErrors.eth.userRejectedRequest('MetaMask Message Signature: User denied message signature.'))
case 'errored':
return reject(new Error(`MetaMask Message Signature: ${data.error}`))
default:
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
"3box/ipfs/ipld-zcash/zcash-bitcore-lib/lodash": "^4.17.12"
},
"dependencies": {
"3box": "^1.10.2",
"@babel/runtime": "^7.5.5",
"@material-ui/core": "1.0.0",
"@sentry/browser": "^4.1.1",
"@zxing/library": "^0.8.0",
"3box": "^1.10.2",
"abi-decoder": "^1.2.0",
"abortcontroller-polyfill": "^1.3.0",
"asmcrypto.js": "^2.3.2",
Expand Down Expand Up @@ -85,6 +85,7 @@
"eth-block-tracker": "^4.4.2",
"eth-contract-metadata": "^1.9.2",
"eth-ens-namehash": "^2.0.8",
"eth-json-rpc-errors": "^1.1.0",
"eth-json-rpc-filters": "^4.1.0",
"eth-json-rpc-infura": "^4.0.1",
"eth-json-rpc-middleware": "^4.2.0",
Expand Down Expand Up @@ -112,7 +113,7 @@
"gaba": "^1.6.0",
"human-standard-token-abi": "^2.0.0",
"jazzicon": "^1.2.0",
"json-rpc-engine": "^5.1.3",
"json-rpc-engine": "^5.1.4",
"json-rpc-middleware-stream": "^2.1.1",
"jsonschema": "^1.2.4",
"lodash.debounce": "^4.0.8",
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9573,6 +9573,13 @@ eth-json-rpc-errors@^1.0.1:
dependencies:
fast-safe-stringify "^2.0.6"

eth-json-rpc-errors@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/eth-json-rpc-errors/-/eth-json-rpc-errors-1.1.0.tgz#2a4291fb20c0483c99b53286a814ed14ca4efb2e"
integrity sha512-AAA76BmwwSR5Mws+ivZUYxoDwMygDuMWxSTEmqDXhRPTExSWe5wuJLT/rSfvPSy9+owSudy67JmyRQ02RAOOYQ==
dependencies:
fast-safe-stringify "^2.0.6"

eth-json-rpc-filters@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/eth-json-rpc-filters/-/eth-json-rpc-filters-4.1.0.tgz#e7357a38983cde29858818dc55d394b9cf47c0f0"
Expand Down Expand Up @@ -15000,6 +15007,16 @@ json-rpc-engine@^5.1.3:
promise-to-callback "^1.0.0"
safe-event-emitter "^1.0.1"

json-rpc-engine@^5.1.4:
version "5.1.4"
resolved "https://registry.yarnpkg.com/json-rpc-engine/-/json-rpc-engine-5.1.4.tgz#c18d1959eb175049fa7301d4866931ae2f879e47"
integrity sha512-nBFWYJ1mvlZL7gqq0M9230SxedL9CbSYO1WgrFi/C1Zo+ZrHUZWLRbr7fUdlLt9TC0G+sf/aEUeuJjR2lHsMvA==
dependencies:
async "^2.0.1"
eth-json-rpc-errors "^1.1.0"
promise-to-callback "^1.0.0"
safe-event-emitter "^1.0.1"

json-rpc-error@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/json-rpc-error/-/json-rpc-error-2.0.0.tgz#a7af9c202838b5e905c7250e547f1aff77258a02"
Expand Down