Running geth
, it's easy to see what its implementation of JSON-RPC does on errors:
$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_compileSolidity","params":["contract test { function multiply(uint a) returns(uint d) { rxturn a * 7; } }"],"id":1}' http://localhost:8545
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"solc: exit status 1\n\u003cstdin\u003e:1:72: Error: Expected token Semicolon got 'Mul'\ncontract test { function multiply(uint a) returns(uint d) { rxturn a * 7; } }\n ^\n"}}
$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "lxtest"],"id":1}' http://localhost:8545
{"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"invalid blocknumber \"lxtest\""}}
$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]}' http://localhost:8545
{"jsonrpc":"2.0","error":{"code":-32700,"message":"missing request id"}}
We get a JSON response containing an error
object rather than the expected output, where error
includes an integer code
and a descriptive message
.
But (am I blind?) I can't seem to documentation of this behavior in the spec, or any information on the codes.
Is error behavior in JSON-RPC standard across implementations? Can one safely rely on the code
/message
response format, even if the codes have not been fully worked out?
Thanks, and apologies if, not unusually, I'm just not looking in obvious right places.
geth
uses (although necessarily not all of the specific error codes). i had wanted to log in tonight to mark that answer correct, because i think it is, but alas the answer seems to have been deleted.