Metamask-extension: MetaMask does not seem to properly follow JSON-RPC specification

Created on 29 Jun 2018  路  5Comments  路  Source: MetaMask/metamask-extension

Expected Behaviour

The call

web3.currentProvider.sendAsync({id: 1, method: "does_not_exist", params: []}, console.log)

returns

{
  "id": 1,
  "error": {
    "code": -32601,
    "message": "JSON-RPC method not found"
  }
}

_(obviously, the actual content string of the message field is not specified by the standard, but something akin to this would probably be the most understandable)_

Actual Behaviour

This call returns

{
  "id": 1,
  "error": {
    "code": -32603,
    "message": "Internal JSON-RPC error."
  }
}

This means that MetaMask (or possibly one of its dependencies) does not properly follow the JSON-RPC Spec.

Browser+OS used

This is using MetaMask version 4.8.0 on FireFox on Manjaro Linux, but I doubt this problem is stack-specific.

Most helpful comment

Hi @Qqwy, thanks for taking the time to file this issue. We use the following logic for handling errors in MetaMask:

const RPC_ERRORS = {
  1: 'An unauthorized action was attempted.',
  2: 'A disallowed action was attempted.',
  3: 'An execution error occurred.',
  [-32600]: 'The JSON sent is not a valid Request object.',
  [-32601]: 'The method does not exist / is not available.',
  [-32602]: 'Invalid method parameter(s).',
  [-32603]: 'Internal JSON-RPC error.',
  [-32700]: 'Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.',
  internal: 'Internal server error.',
  unknown: 'Unknown JSON-RPC error.',
}

Note that we do support the -32601 error code, but the response coming from the RPC engine (kumavis/json-rpc-engine) in your example is returning -32603.

I've opened up an issue against the RPC engine that you can track here: kumavis/json-rpc-engine#6.

All 5 comments

Hi @Qqwy, thanks for taking the time to file this issue. We use the following logic for handling errors in MetaMask:

const RPC_ERRORS = {
  1: 'An unauthorized action was attempted.',
  2: 'A disallowed action was attempted.',
  3: 'An execution error occurred.',
  [-32600]: 'The JSON sent is not a valid Request object.',
  [-32601]: 'The method does not exist / is not available.',
  [-32602]: 'Invalid method parameter(s).',
  [-32603]: 'Internal JSON-RPC error.',
  [-32700]: 'Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.',
  internal: 'Internal server error.',
  unknown: 'Unknown JSON-RPC error.',
}

Note that we do support the -32601 error code, but the response coming from the RPC engine (kumavis/json-rpc-engine) in your example is returning -32603.

I've opened up an issue against the RPC engine that you can track here: kumavis/json-rpc-engine#6.

In hindsight, we should probably leave this issue open as well as a means to verify that the upstream changes to json-rpc-engine are built and released as part of a future MetaMask release. Thanks again for the issue @Qqwy.

Thanks for your quick response! I will be tracking the process of this issue and the upstream one :-).

Are there no eth-specific error codes?

As of v8.1.9, OP's code snippet will return an error object

{
  "code": -32601,
  "message": "The method 'does_not_exist' does not exist / is not available.",
  "data": {data_object}
}
Was this page helpful?
0 / 5 - 0 ratings