ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.95k stars 1.85k forks source link

Error Processing Error when Error thrown from Blockchain Network #3293

Open saiakhil2012 opened 2 years ago

saiakhil2012 commented 2 years ago

Ethers Version

v5.6.9

Search Terms

error handling

Describe the Problem

When there are errors received from Blockchain network, getting an error as, Error: processing response error <>

Following is an example, let's say, to present this problem, trying to write data to Blockchain and the sender's account does not have enough funds.

Using the Ethers.js library, making such a call to Smart contract function generates following error,

(node:87811) UnhandledPromiseRejectionWarning: Error: processing response error (body="{\"id\":56,\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"sender doesn't have enough funds to send tx. The upfront cost is: 721480000000000 and the sender's account only has: 0\",\"code\":-32000,\"data\":{\"stack\":\"Error: sender doesn't have enough funds to send tx. The upfront cost is: 721480000000000 and the sender's account only has: 0\n at VM. (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/lib/runTx.ts:114:11)\n at step (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:33:23)\n at Object.next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:14:53)\n at fulfilled (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:5:58)\n at runMicrotasks ()\n at processTicksAndRejections (internal/process/task_queues.js:93:5)\",\"name\":\"Error\"}}}", error={"code":-32000,"data":{"stack":"Error: sender doesn't have enough funds to send tx. The upfront cost is: 721480000000000 and the sender's account only has: 0\n at VM. (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/lib/runTx.ts:114:11)\n at step (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:33:23)\n at Object.next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:14:53)\n at fulfilled (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:5:58)\n at runMicrotasks ()\n at processTicksAndRejections (internal/process/task_queues.js:93:5)","name":"Error"}}, requestBody="{\"method\":\"eth_sendRawTransaction\",\"params\":[\"0xf8cb808504a817c800828cea946c324098fc582ca85ad6213cc7f6ebce0170d7c280b864a41368620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b4e6577204772656574696e672046726f6d204574686572732e6a730000000000820a95a044ec8973f745787e0004f126edd588e834485e59b8adb2a39d62f48c2fb692e7a01dcca7da8efff39c2e8b5a95694d6c7bae9da1e49a4d20616ce5a0ff17519f14\"],\"id\":56,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="http://127.0.0.1:7545", code=SERVER_ERROR, version=web/5.6.1) at Logger.makeError (/Users/malepatia/Workspace/ethers-custom/ethers.js/packages/ethers/node_modules/@ethersproject/logger/lib/index.js:233:21) at Logger.throwError (/Users/malepatia/Workspace/ethers-custom/ethers.js/packages/ethers/node_modules/@ethersproject/logger/lib/index.js:242:20) at /Users/malepatia/Workspace/ethers-custom/ethers.js/packages/ethers/node_modules/@ethersproject/web/lib/index.js:305:32 at step (/Users/malepatia/Workspace/ethers-custom/ethers.js/packages/ethers/node_modules/@ethersproject/web/lib/index.js:33:23) at Object.next (/Users/malepatia/Workspace/ethers-custom/ethers.js/packages/ethers/node_modules/@ethersproject/web/lib/index.js:14:53) at fulfilled (/Users/malepatia/Workspace/ethers-custom/ethers.js/packages/ethers/node_modules/@ethersproject/web/lib/index.js:5:58) at processTicksAndRejections (internal/process/task_queues.js:93:5) (Use node --trace-warnings ... to show where the warning was created) (node:87811) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:87811) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Whereas, performing the same call at JSON RPC level, i.e doing a direct curl call, getting an error directly,

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0xf8cb808504a817c800828cea946c324098fc582ca85ad6213cc7f6ebce0170d7c280b864a41368620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b4e6577204772656574696e672046726f6d204574686572732e6a730000000000820a95a044ec8973f745787e0004f126edd588e834485e59b8adb2a39d62f48c2fb692e7a01dcca7da8efff39c2e8b5a95694d6c7bae9da1e49a4d20616ce5a0ff17519f14"],"id":56}' --header "Content-Type: application/json" http://localhost:7545

{"id":56,"jsonrpc":"2.0","error":{"message":"sender doesn't have enough funds to send tx. The upfront cost is: 721480000000000 and the sender's account only has: 0","code":-32000,"data":{"stack":"Error: sender doesn't have enough funds to send tx. The upfront cost is: 721480000000000 and the sender's account only has: 0\n at VM. (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/lib/runTx.ts:114:11)\n at step (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:33:23)\n at Object.next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:14:53)\n at fulfilled (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/runTx.js:5:58)\n at runMicrotasks ()\n at processTicksAndRejections (internal/process/task_queues.js:93:5)","name":"Error"}}}

Is there some gap between what is expected as part of error from the Blockchain network or some other aspect missing when processing the error itself in Ethers.js?

Thanks in advance for taking a look Akhil

Code Snippet

No response

Contract ABI

No response

Errors

No response

Environment

Ganache

Environment (Other)

No response

ricmoo commented 2 years ago

This looks like that node has changed the error string used to indicate insufficient intrinsic cost; what version and of what node are you using? I.E. geth vs parity vs etc.

Ethers must maintain a series of strings internally since there is no standard for the errors returned, so whenever a node changes their error strings, ethers needs to be updated.

saiakhil2012 commented 2 years ago

I am directly using Ganache. Version of Ganache is 2.5.4