Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot use 'in' operator to search for 'originalError' in null #6433

Closed
lvivo639 opened this issue Sep 16, 2023 · 3 comments · Fixed by #6905 or #7147
Closed

TypeError: Cannot use 'in' operator to search for 'originalError' in null #6433

lvivo639 opened this issue Sep 16, 2023 · 3 comments · Fixed by #6905 or #7147
Assignees
Labels
4.x 4.0 related Bug Addressing a bug

Comments

@lvivo639
Copy link

Expected behavior

Throwing error with message that my transaction/gas estimating was reverted

Actual behavior

\web3-errors\src\errors\contract_errors.ts:163 line throws next error:

 if ('originalError' in error.data) {
TypeError: Cannot use 'in' operator to search for 'originalError' in null

It can be thrown by web3.eth..estimateGas() or w3.eth.sendSignedTransaction().

My transaction was reverted and I just logged it in console (in library code) to understand what happened. Error object is:

{
  "code": -32000,
  "message": "execution reverted",
  "data": null
}

As soon as typeof null === 'object' is true web3-errors library throws an error above in this code:

if (typeof error.data === 'object') {
            let originalError;
            if ('originalError' in error.data) {

Error throwed in web3-errors\src\errors\contract_errors.ts:163

Steps to reproduce the behavior

I don't actually know why transaction is reverted. Code throws it randomly.

Logs

root\node_modules\web3-errors\src\errors\contract_errors.ts:163
                        if ('originalError' in error.data) {
                    ^
TypeError: Cannot use 'in' operator to search for 'originalError' in null
    at new Eip838ExecutionError (root\node_modules\web3-errors\src\errors\contract_errors.ts:163:21)
    at new ContractExecutionError (root\node_modules\web3-errors\src\errors\contract_errors.ts:225:3)
    at Function._isReverted (root\node_modules\web3-core\src\web3_request_manager.ts:432:48)
    at Web3RequestManager._processJsonRpcResponse (root\node_modules\web3-core\src\web3_request_manager.ts:361:35)
    at Web3RequestManager.<anonymous> (root\node_modules\web3-core\src\web3_request_manager.ts:206:16)
    at Generator.next (<anonymous>)
    at fulfilled (root\node_modules\web3-core\lib\commonjs\web3_request_manager.js:21:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Environment

npm - 9.8.1
node - 18.17.1
web3 - 4.1.1
OS - Windows 10

@jdevcs jdevcs added 4.x 4.0 related Bug Addressing a bug labels Sep 18, 2023
@jdevcs
Copy link
Contributor

jdevcs commented Sep 18, 2023

@lvivo639 Thanks for details, we will fix this.

@Alfxjx
Copy link
Contributor

Alfxjx commented Mar 8, 2024

The in operator looks for the key in an object, but unfortunately null is also an object, which means typeof null === 'object'.
Would like to fix this. can I open a new PR for this?

@jdevcs
Copy link
Contributor

jdevcs commented Mar 12, 2024

@Alfxjx sure open PR for its fix, thanks

Alfxjx added a commit to Alfxjx/web3.js that referenced this issue Mar 16, 2024
@jdevcs jdevcs self-assigned this Jul 11, 2024
jdevcs added a commit that referenced this issue Jul 11, 2024
* fix(web3-errors): handle the undefined data in Eip838ExecutionError constructor(#6433)

* doc: update changelog

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Muhammad Altabba <[email protected]>
Co-authored-by: Junaid <[email protected]>
jdevcs added a commit that referenced this issue Jul 12, 2024
…7147)

* fix(web3-errors): the undefined data in Eip838ExecutionError (#6905)

* fix(web3-errors): handle the undefined data in Eip838ExecutionError constructor(#6433)

* doc: update changelog

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Muhammad Altabba <[email protected]>
Co-authored-by: Junaid <[email protected]>

* changelog update

---------

Co-authored-by: Xu Jianxiang <[email protected]>
Co-authored-by: Muhammad Altabba <[email protected]>
Co-authored-by: Oleksii Kosynskyi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug
Projects
None yet
4 participants