Revert Error response processing
See original GitHub issueHi,
Trying to handle revert errors on gas estimate on-chain, but documentation does not seem to have anything clear on this.
Made a few tests but i don’t have much consistency, maybe we could enhance documentation and/or error handling, or even adding code example ?
I even tried to understand ethers error logger from https://github.com/ethers-io/ethers.js/blob/eb432aa1f44ad2cc268d000b266eae9b03db1d17/packages/web/src.ts/index.ts
For example, a Uniswap Router Swap revert with “Too little Received” can be parsed to understand issue. I ended up handling pretty ugly like this :
const potentialError =
typeof error === 'string'
? error.match(regexExtract)
: typeof error.message === 'string'
? error.message.match(regexExtract)
: typeof error.error?.body === 'string'
? JSON.parse(error.error?.body)
: error.error?.message || "No revert reason found";
But a revert for whatever reason (token error ?) looks different in error type :
processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":2052,\"error\":{\"code\":-32000,\"message\":\"execution reverted\"}}\n", error={"code":-32000}, requestBody="{\"method\":\"eth_estimateGas\",\"params\":[{\"type\":\"0x2\",\"from\":\"0xf0000000\",\"to\":\"0x12000000\",\"data\":\"0x0000\"}],\"id\":2052,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="http://192.168.1.3:8545", code=SERVER_ERROR, version=web/5.5.0)
So, am i missing something on ethers error on gas estimate ? Or should we enhance documentation ? Also a simple Typescript type Error would be great to parse.
Thanks !
PS : addresses are fine, just changed them for privacy matters
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
I’m working on a fix to help consolidate these. The Hardhat error will be hard to process in its current state, but I’ll make a request for them to format it so it is machine readable (in addition to human-readable).
Was this error fixed or is it still open?