Skip to content

Conversation

randydu
Copy link

@randydu randydu commented Mar 20, 2025

The errorData could be null when the error is thrown from hardhat / ethers.js, hence a "Cannot read properties of null (reading 'data')" error will occur when setting returnData at line 67.

Example error causing the issue:

{
code: 'UNKNOWN_ERROR',
error: {
    code: -32000,
    message: "Nonce too high. Expected nonce to be 0 but got 33. Note that transactions can't be queued when automining.",
    data: {
      message: "Nonce too high. Expected nonce to be 0 but got 33. Note that transactions can't be queued when automining.",
      data: null <===  HERE is a null data!!!!
    }
  },
payload: {
    method: 'eth_sendRawTransaction',
    params: [
      '0x02f8b2827a6921843b9aca00843e9a078083015644944abeaca4b05d8fa4ced09d26ad28ea298e8afac880b844a9059cbb0000000000000000000000009965507d1a55bcc2695c58ba16fb37d819b0a4dc0000000000000000000000000000000000000000000000000000000000000064c001a03c032ec0cd43679f7400e1c90a8c9c07fe3d87ed4e0bf78ec5097046cf16d1eaa03cc5e482a939684ef216bfdeb72cb15fd36558a9df53de3745e3a27eb60f7869'
    ],
    id: 28,
    jsonrpc: '2.0'
  },
  shortMessage: 'could not coalesce error'
}

The errorData could be null when the error is thrown from hardhat / ethers.js, hence a "Cannot read properties of null (reading 'data')" error will occur when setting returnData in the line 67.

Example error causing the issue:
```json
{
code: 'UNKNOWN_ERROR',
  error: {
    code: -32000,
    message: "Nonce too high. Expected nonce to be 0 but got 33. Note that transactions can't be queued when automining.",
    data: {
      message: "Nonce too high. Expected nonce to be 0 but got 33. Note that transactions can't be queued when automining.",
      data: null
    }
  },
  payload: {
    method: 'eth_sendRawTransaction',
    params: [
      '0x02f8b2827a6921843b9aca00843e9a078083015644944abeaca4b05d8fa4ced09d26ad28ea298e8afac880b844a9059cbb0000000000000000000000009965507d1a55bcc2695c58ba16fb37d819b0a4dc0000000000000000000000000000000000000000000000000000000000000064c001a03c032ec0cd43679f7400e1c90a8c9c07fe3d87ed4e0bf78ec5097046cf16d1eaa03cc5e482a939684ef216bfdeb72cb15fd36558a9df53de3745e3a27eb60f7869'
    ],
    id: 28,
    jsonrpc: '2.0'
  },
  shortMessage: 'could not coalesce error'
}
```
@randydu randydu marked this pull request as draft March 20, 2025 23:48
@randydu
Copy link
Author

randydu commented Mar 20, 2025

I have not double checked if my fix really works for the error, it seems the error is not raised from line 67.

Here is the stack trace when the error is thrown:

stacktrace": [
          "TypeError: Cannot read properties of null (reading 'data')",
          "    at e.getDataFromError (file:///work/blocpal/tokendev/api/node_modules/ethers-decode-error/dist/index.mjs:1:5439)",
          "    at file:///work/blocpal/tokendev/api/node_modules/ethers-decode-error/dist/index.mjs:1:5647",

@superical
Copy link
Owner

Thanks @randydu for creating this pull request!😊 Just want to check if I understood the issue correctly, the issue you’re facing happens when the nonce is incorrectly passed to Ethers when sending a transaction and the data field in the error object thrown by Ethers is null but the library is attempts to from it. Did I understand the issue correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants