Ethers.js: Change in error message

Created on 15 Sep 2020  路  4Comments  路  Source: ethers-io/ethers.js

Sorry to bother about errors again, but error messages just went from readable to unreadable.

I have two error messages of a same script, before and post ethers.js minor upgrade (i've added quick new line characters to make it viewable here instead of horizontal scroll)

Some previous version (web/5.0.2):

processing response error (body={"jsonrpc":"2.0","error":{"code":-32010,"message":"Transaction nonce is too low. Try 
incrementing the nonce."},"id":44}, error=
{"code":-32010}, requestBody="{\"method\":\"eth_sendRawTransaction\",\"params\":
[\"0xf9016a828334808301a012944cada3b127fd31921127409a86a71d0a7cb7a85b80b90104e60e2b52000000000000000
000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000
0000000000000000000100000000000000000000000016c487299760dd3383f188249a4d873d3e29f391000000000000
000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000
0000000000000000003dfcb407b3e3817427649829cb1b4b0eeba4b65e00000000000000000000000000000000000000
000000000000000000000000008228bca0b90cfbeebbee57a0179252d61fb028f878f7b00f6468d5399e15ab225ed5c7e8a
031af41679a9e868af5d02c67accab79e61b5356d63c554bd9c9b829a9acbc521\"],\"id\":44,\"jsonrpc\":\"2.0\"}", 
requestMethod="POST", url="https://infura.io", code=SERVER_ERROR, version=web/5.0.2)

Latest version (web/5.0.6):

processing response error (body="0x7b226a736f6e727063223a22322e30222c226572726f72223a7b22636f6465223a2d33323031302c226d657373
616765223a225472616e73616374696f6e206e6f6e636520697320746f6f206c6f772e2054727920696e6372656d656e746
96e6720746865206e6f6e63652e227d2c226964223a333634337d0a", error={"code":-32010}, requestBody="
{\"method\":\"eth_sendRawTransaction\",\"params\":
[\"0xf9016a828334808301a012944cada3b127fd31921127409a86a71d0a7cb7a85b80b90104e60e2b52000000000000000
000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000
0000000000000000000100000000000000000000000016c487299760dd3383f188249a4d873d3e29f391000000000000
000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000
0000000000000000003dfcb407b3e3817427649829cb1b4b0eeba4b65e00000000000000000000000000000000000000
000000000000000000000000008228bca0b90cfbeebbee57a0179252d61fb028f878f7b00f6468d5399e15ab225ed5c7e8a
031af41679a9e868af5d02c67accab79e61b5356d63c554bd9c9b829a9acbc521\"],\"id\":3643,\"jsonrpc\":\"2.0\"}", 
requestMethod="POST", url="https://infura.io", code=SERVER_ERROR, version=web/5.0.6)

Before the upgrade, I could simply do if(error.message.includes('Transaction nonce is too low')) {} in my logic. Now the body is not parsed format.

Also I wanted to know a good way to install an older version of ethers (downgrade few minor versions) incase situation is very critical and it's super urgent to get it working no matter what.

bug fixed

All 4 comments

That is strange. It is encoding it as hex (decoded: '{"jsonrpc":"2.0","error":{"code":-32010,"message":"Transaction nonce is too low. Try incrementing the nonce."},"id":3643}\n').

I'll figure out why this is happening and fix it shortly.

You shouldn't need any string matching. When things are working correctly, you should be able to use if (error.code === Logger.errors.NONCE_EXPIRED) { } to accomplish the same thing, and then ethers can be responsible for normalizing the errors. :)

You shouldn't need any string matching. When things are working correctly, you should be able to use if (error.code === Logger.errors.NONCE_EXPIRED) { } to accomplish the same thing, and then ethers can be responsible for normalizing the errors. :)

That's really awesome!

This should be available in 5.0.14 now. :)

I found the code path that was skipping the human-readability of error messages in some cases and updated the string matching for normalizing the errors and making sure the Signer and FallbackProvider properly forward blockchain errors.

Let me know if you have any problems. :)

Closing this now, but please re-open if you are still having issues.

Thanks! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thegostep picture thegostep  路  3Comments

thegostep picture thegostep  路  3Comments

jochenonline picture jochenonline  路  3Comments

dagogodboss picture dagogodboss  路  3Comments

naddison36 picture naddison36  路  3Comments