question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formatting revert error objects

See original GitHub issue

When a contract method reverts, it throws an error: “processing response error”.

In the v5, the error.message contains lot of stuff including the actual rpc response from the node. While in v4, error.message contained only the error message string from the JSON RPC error.

try {
    await contract.methodThatReverts()
} catch (err) {
    console.log(err.message); // prints ethers error message containing the json rpc response as it is (along with error stacks from node if sent)
    console.log(err.error.message); // short and sweet error message
}

ethers v5 revert error object:

Error: processing response error (body={"id":247,"jsonrpc":"2.0","error":{"message":"VM Exception while processing transaction: revert invalid start block number","code":-32000,"data":{"stack":"RuntimeError: VM Exception while processing transaction: revert invalid start block number\n    at Function.RuntimeError.fromResults (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/ganache-core/lib/utils/runtimeerror.js:89:13)\n    at module.exports (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/ganache-core/lib/utils/gas/guestimation.js:142:32)","name":"RuntimeError"}}}, error={"code":-32000,"data":{"stack":"RuntimeError: VM Exception while processing transaction: revert invalid start block number\n    at Function.RuntimeError.fromResults (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/ganache-core/lib/utils/runtimeerror.js:89:13)\n    at module.exports (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/ganache-core/lib/utils/gas/guestimation.js:142:32)","name":"RuntimeError"}}, code=SERVER_ERROR, version=web/5.0.0-beta.141)
    at Logger.makeError (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/logger/lib/index.js:178:21)
    at Logger.throwError (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/logger/lib/index.js:187:20)
    at /Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/web/lib/index.js:181:32
    at step (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/web/lib/index.js:33:23)
    at Object.next (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/web/lib/index.js:14:53)
    at fulfilled (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/web/lib/index.js:5:58)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  reason: 'processing response error',
  code: 'SERVER_ERROR',
  body: {
    id: 247,
    jsonrpc: '2.0',
    error: {
      message: 'VM Exception while processing transaction: revert invalid start block number',
      code: -32000,
      data: [Object]
    }
  },
  error: Error: VM Exception while processing transaction: revert invalid start block number
      at getResult (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:70:21)
      at /Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/web/lib/index.js:175:46
      at step (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/web/lib/index.js:33:23)
      at Object.next (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/web/lib/index.js:14:53)
      at fulfilled (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/@ethersproject/web/lib/index.js:5:58)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
    code: -32000,
    data: {
      stack: 'RuntimeError: VM Exception while processing transaction: revert invalid start block number\n' +
        '    at Function.RuntimeError.fromResults (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/ganache-core/lib/utils/runtimeerror.js:89:13)\n' +
        '    at module.exports (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/esn-contracts/node_modules/ganache-core/lib/utils/gas/guestimation.js:142:32)',
      name: 'RuntimeError'
    }
  }
}

ethers v4 revert error object (from a different project) looks like:

Error: VM Exception while processing transaction: revert insufficient balance
    at getResult (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/ethers/providers/json-rpc-provider.js:40:21)
    at exports.XMLHttpRequest.request.onreadystatechange (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/ethers/utils/web.js:111:30)
    at exports.XMLHttpRequest.dispatchEvent (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
    at setState (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:610:14)
    at IncomingMessage.<anonymous> (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
    at IncomingMessage.emit (events.js:333:22)
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  code: -32000,
  data: {
    stack: 'RuntimeError: VM Exception while processing transaction: revert insufficient balance\n' +
      '    at Function.RuntimeError.fromResults (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/ganache-core/lib/utils/runtimeerror.js:89:13)\n' +
      '    at module.exports (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/ganache-core/lib/utils/gas/guestimation.js:142:32)',
    name: 'RuntimeError'
  },
  url: 'http://localhost:7566',
  body: '{"method":"eth_estimateGas","params":[{"from":"0x5C2807c2E86ECDdDA3537EdFAA7752Ac9bbF9fcD","to":"0x73f898B5C93115eE95ec02cE0811E4D07fC4aEF0","data":"0xa9059cbb000000000000000000000000ff9861f72d4989a94a20ec19f6005b15b61c1c6b000000000000000000000000000000004b3b4ca85a86c47a098a224000000000"}],"id":50,"jsonrpc":"2.0"}',
  responseText: '{"id":50,"jsonrpc":"2.0","error":{"message":"VM Exception while processing transaction: revert insufficient balance","code":-32000,"data":{"stack":"RuntimeError: VM Exception while processing transaction: revert insufficient balance\\n    at Function.RuntimeError.fromResults (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/ganache-core/lib/utils/runtimeerror.js:89:13)\\n    at module.exports (/Users/sohamzemse/soham/workspace/blockchain/ethereum/timeally/node_modules/ganache-core/lib/utils/gas/guestimation.js:142:32)","name":"RuntimeError"}}}'
}

Though I can access the revert message from err.error.message for now, I wanna confirm if reverts will be formatted in future, it might cause tests I’m writing to break.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ricmoocommented, Jun 6, 2020

That part should not change.

The revert reason at some point may be also available in the main error, but this requires a bit more effort, since it isn’t being fed back in a nice machine readable way and each backend seems to choose their own format. 😦

0reactions
ricmoocommented, Aug 24, 2021

I think this issue may be stale, so I’m closing it. If not, please feel free to re-open or start a new issue/discussion.

Thanks! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error object formatting in general - javascript - Stack Overflow
Main idea is to pass error object from Model to View . Simple approach would be to pass just array of errors: [1,2,6]...
Read more >
revert - CSS: Cascading Style Sheets - MDN Web Docs
The revert CSS keyword reverts the cascaded value of the property from its current value to the value the property would have had...
Read more >
Excel formatting and features that are not transferred to other ...
All formatting, graphics, objects, and other worksheet contents are lost. The euro symbol will be converted to a question mark.
Read more >
If page formatting keeps changing on Mac - Apple Support
Select a paragraph that uses the formatting you want. · Choose Format > Copy Style (from the Format menu at the top of...
Read more >
Interface - Ethers.js
Most developers won't need this, as the decodeFunctionResult will automatically decode errors if the data represents a revert. // Decoding result data (e.g. ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found