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

Uncaught TypeError: err.data.substring is not a function #3742

Closed
gabmontes opened this issue Oct 13, 2020 · 28 comments
Closed

Uncaught TypeError: err.data.substring is not a function #3742

gabmontes opened this issue Oct 13, 2020 · 28 comments
Assignees
Labels
Bug Addressing a bug Investigate P2 Medium severity bugs

Comments

@gabmontes
Copy link
Contributor

The following line throws an Uncaught TypeError:

https://github.com/ethereum/web3.js/blob/4615f2d35c455bd81cb04f0ab8d8d2c0b140e33a/packages/web3-core-method/src/index.js#L630

The error is only thrown when handleRevert is activated in the contract and the transaction reverts. In that case err.data is an object with this format: {name, stack, 0x...: {error, program_counter, return} }. If handleRevert is false, then err.data is a string and it is properly parsed.

Using Geth 1.9, ganache-cli@6.8.2 and web3@1.3.0.

@spacesailor24
Copy link
Contributor

Hi there, the bug you're describing makes sense, do you have example code we can use to debug?

Thank you for reporting this!

@spacesailor24 spacesailor24 added the Bug Addressing a bug label Oct 29, 2020
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Dec 29, 2020
@danielspk
Copy link

Sorry but this bug was not fixed

@github-actions github-actions bot removed the Stale Has not received enough activity label Dec 30, 2020
@nicos99
Copy link
Contributor

nicos99 commented Jan 24, 2021

The bug seems to have been introduced on version 1.2.10 and still exist on 1.3.3.
You can find here some web code to reproduce the issue.

  • compile the contract call-revert.sol,
  • deploy the contract on a test net (event a localy one),
  • set in call-revert-bug.html variable sampleContractAdr with the deployed contract's addresse,
  • click on 'Call Start() !' button while speed value > 100

@TbLtzk
Copy link

TbLtzk commented Feb 2, 2021

Seeing the same issue. In our case it occurs when we provide an rpc url that

  1. has a geth client running
  2. does not expose rpc interface

r-czajkowski added a commit to keep-network/keep-core that referenced this issue Feb 5, 2021
The `TokenGeyser.unstakeQuery` throws an error in case when eg. the
amount param is greater than real user's stake or when the user stakes
KEEP in block `X` and call unstakeQuery in block `X` (`SafeMath:
division by zero` error is thrown.). The web3 parses the error message
in the wrong way when the `hanleRevert` option is enabled [1]. So here
we clone the rewards contract instance and disable the `hanldeRevert`
option.
References:
[1]: web3/web3.js#3742
@ivarcontessotto
Copy link

Encountered this issue as well and had to turn the 'handleRevert' property on the web3 provider to false like @gabmontes meantioned. I would like to use the revert reason feature but this error crashes the whole application and I was unable to catch it with a try-catch around 'await myMethod.send(...)'.

@github-actions
Copy link

github-actions bot commented May 5, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label May 5, 2021
@gabmontes
Copy link
Contributor Author

Hey bot, do not close this. The bug is not resolved yet.

@github-actions github-actions bot removed the Stale Has not received enough activity label May 6, 2021
@anycryptodeveloper
Copy link

The bug is not resolved yet.

@rayyan808
Copy link

Hello, encountering the same bug on latest web3, specifically in the transaction callback when calling a uint256 value from the contract:

 submitVote = async (e) => {
     e.preventDefault();
     if(this.state.proofGenerated && this.state.proof !== null && this.state.candidateID !== null){
       let result = await Election.methods
       .publicKey().call({from: this.state.accountList[this.state.account], gas: 40000}).catch((err) => { console.log("Error calling publicKey from contract: " + err) });
       const json = JSONbig.parse(result);
       const publicKey = new paillierBigint.PublicKey(json.n, json.g);
       let voteValue = publicKey.encrypt(this.state.candidateID);
       console.log("voteValue: " + voteValue + "publicKey: " + publicKey + "")
         await Election.methods
          .submitVote(this.state.proof.proof, this.state.proof.inputs, voteValue)
          .send({ from: this.state.accountList[this.state.account], gas: 400000 }, (receipt) => {
            /* Callback from transaction*/
            console.log(receipt);
          }).catch((err) => { console.log("Error apply function submitVote: " + err); });
       
          console.log("End of Conduct\n");
        }
    }

Uncaught TypeError: err.data.substring is not a function
at sendTxCallback (index.js:510)
at Object.callback (index.js:303)
at index.js:114
at Array.forEach ()
at WebsocketProvider.push../node_modules/web3-providers-ws/lib/index.js.WebsocketProvider._onMessage (index.js:102)


@dougbtv
Copy link

dougbtv commented Jun 23, 2021

Just another data point, I wound up encountering this while developing in truffle, and I simplified a contract method to:

    function faker(bytes3 _fake) public view returns(bytes3) {
        return (_fake);
    }

And then I try to execute that function and I get...

truffle(develop)> let instance = await MyContract.deployed()
undefined
truffle(develop)> const paintdata = await instance.faker([1,2,3])
Uncaught TypeError: param.substring is not a function
    at evalmachine.<anonymous>:1:18
    at evalmachine.<anonymous>:2:49
    at sigintHandlersWrap (vm.js:273:12)
    at Script.runInContext (vm.js:140:14)
    at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:270:1)
    at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:285:1)
    at bound (domain.js:413:15)
    at REPLServer.runBound [as eval] (domain.js:424:12)
    at REPLServer.onLine (repl.js:817:10)
    at REPLServer.emit (events.js:315:20)
    at REPLServer.EventEmitter.emit (domain.js:467:12)
    at REPLServer.Interface._onLine (readline.js:337:10)
    at REPLServer.Interface._line (readline.js:666:8)
    at REPLServer.Interface._ttyWrite (readline.js:1010:14) {
  hijackedStack: 'TypeError: param.substring is not a function\n' +
    '    at ABICoder.formatParam (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/lib/index.js:239:1)\n' +
    '    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/lib/index.js:100:1\n' +
    '    at Array.map (<anonymous>)\n' +
    '    at ABICoder.encodeParameters (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/lib/index.js:94:1)\n' +
    '    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:439:1\n' +
    '    at Array.map (<anonymous>)\n' +
    '    at Object._encodeMethodABI (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:438:6)\n' +
    '    at Object._processExecuteArguments (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:701:1)\n' +
    '    at Object._executeMethod (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:720:1)\n' +
    '    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/contract/lib/execute.js:143:1\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:93:5)'
}

@rayyan808
Copy link

Bug still persists

@weidaix
Copy link

weidaix commented Jul 28, 2021

Bug still present. Any ETA on resolution?

@musnit
Copy link

musnit commented Aug 11, 2021

bump

@Mereep
Copy link

Mereep commented Sep 8, 2021

Getting this error when running truffle test (web3@1.3.4).

@itseasy21
Copy link

itseasy21 commented Sep 9, 2021

Bump! Getting this error.

Log:

TypeError: param.substring is not a function
    at ABICoder.formatParam (D:\Blockchain-WorkSpace\smart-contract-test\node_modules\web3-eth-abi\lib\index.js:248:35)
    at D:\Blockchain-WorkSpace\smart-contract-test\node_modules\web3-eth-abi\lib\index.js:99:22
    at Array.map (<anonymous>)
    at ABICoder.encodeParameters (D:\Blockchain-WorkSpace\smart-contract-test\node_modules\web3-eth-abi\lib\index.js:93:21)
    at D:\Blockchain-WorkSpace\smart-contract-test\node_modules\web3-eth-contract\lib\index.js:438:20
    at Array.map (<anonymous>)
    at Object._encodeMethodABI (D:\Blockchain-WorkSpace\smart-contract-test\node_modules\web3-eth-contract\lib\index.js:437:8)
    at mintNFT (D:\Blockchain-WorkSpace\smart-contract-test\scripts\mint-nft.js:23:71)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

@bitsandtea
Copy link

bump

@nazarhussain
Copy link
Contributor

nazarhussain commented Sep 17, 2021

I am able to reproduce the error with following hardhat script and running against ganache with npx hardhat --network localhost test

contract CallRevert{
    uint speed;
    
    function Start(uint _speedPercent) public {
        console.log("Start called:", _speedPercent);
        require(_speedPercent <= 100, "speed invalid");
        speed = _speedPercent;
    }
}
const CallRevert = artifacts.require("CallRevert");

describe("Call Error on Revert", function () {
  let accounts;
  let contract; 

  before(async function () {
    accounts = await web3.eth.getAccounts();
    const c = await CallRevert.new();
    contract = new web3.eth.Contract(c.abi, c.address);
  });

  describe("Call Revert", function () {
    it("should throw error when called", async function () {
      contract.handleRevert = true;
      await expect(contract.methods.Start(102).call()).to.be.rejectedWith('speed invalid');
    });

    it("should throw error when sent", async function () {
      contract.handleRevert = true;
      await expect(contract.methods.Start(102).send({from: accounts[0]})).to.be.rejectedWith('speed invalid');
    });
  });
});

The actual error object that appears with Ganahe is.

 {
    stack: 'ProviderError: VM Exception while processing transaction: revert speed invalid\n' +
      '    at HttpProvider.request (/...../)\n' +
      '    at GanacheGasMultiplierProvider.request (/...../)',
    name: 'ProviderError'
  }

@nazarhussain
Copy link
Contributor

The actual response that is sent by the client is:

<     "id": 14,
 <     "jsonrpc": "2.0",
 <     "error": {
 <       "message": "VM Exception while processing transaction: revert speed invalid",
 <       "code": -32000,
 <       "data": {
 <         "0x7d38bce5a39ee329c3f8552f7dc835c7b388d713f8cc033abf08a71a40bae9f9": {
 <           "error": "revert",
 <           "program_counter": 261,
 <           "return": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d737065656420696e76616c696400000000000000000000000000000000000000",
 <           "reason": "speed invalid"
 <         },
 <         "stack": "c: VM Exception while processing transaction: revert speed invalid\n    at Function.c.fromResults (/Users/nazar/.asdf/installs/nodejs/14.17.5/.npm/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\n    at /Users/nazar/.asdf/installs/nodejs/14.17.5/.npm/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:50402",
 <         "name": "c"
 <       }
 <     }
 <   }

@nazarhussain
Copy link
Contributor

The further investigation leads to the fact that latest version of web3@1.5.2 does not include this bug rather it must be in some dependant libraries as reported above for redhat NomicFoundation/hardhat#1910

The following scripts confirms that if we use web3 directly with geth latest version this error can't be reproduced.

Start the geth with following command.

geth --datadir test-chain-dir --dev --http --rpc.txfeecap 0 --allow-insecure-unlock

And use following contract and compile it.

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

contract CallRevert{
    uint speed;
    
    function Start(uint _speedPercent) public {
        require(_speedPercent <= 100, "speed invalid");
        speed = _speedPercent;
    }
}

Run following script.

const Web3 = require("web3");
const web3 = new Web3(Web3.givenProvider || "http://localhost:8545");
const CallRevert = require("../artifacts/contracts/CallRevert.sol/CallRevert.json");

(async () => {
  console.log("%%%%% WEB3: ", web3.version);
  const account = web3.eth.accounts.create("my-pass-phrase");
  web3.eth.accounts.wallet.add(account);

  const accounts = await web3.eth.getAccounts();

  await web3.eth.sendTransaction({
    from: accounts[0],
    to: account.address,
    value: web3.utils.toWei("1234", "ether"),
  });

  console.log(
    "%%%%% account balance: ",
    await web3.eth.getBalance(account.address)
  );

  const contract = new web3.eth.Contract(CallRevert.abi, {
    data: CallRevert.bytecode,
  });

  const contractInstance = await contract
    .deploy({
      arguments: [],
    })
    .send({
      from: account.address,
      gas: 1500000,
      gasPrice: "30000000000000",
    });

  console.log("%%%%% contract address: ", contractInstance.options.address);
  contractInstance.handleRevert = true;
  await contractInstance.methods.Start(102).call();
})().catch((e) => {
  console.error("%%%%% catches error: ", e);
});

It will produce following output.

%%% web3:  1.5.2
%%% account balance:  1234000000000000000000
%%% contract address:  0x291b490f1a38d2b3Eed82d2aC1F34d2abd4c819C
%%% catches error:  Error: Your request got reverted with the following reason string: speed invalid

The above output confirms that web3 works fine directly with geth. So problem lies in some other provider or wrapper.

@nazarhussain
Copy link
Contributor

@gabmontes I am closing this issues after above verification. Feel free to open it if you get more traceable data or you can reproduce it with latest version of web3 and geth directly without any third-party library or provider.

@nicos99
Copy link
Contributor

nicos99 commented Sep 28, 2021

@nazarhussain thanks for the investigative work but I still see an issue (Uncaught TypeError: o.data.substring is not a function) in context explained in my comment of January 25, even with web3 1.5.2. I will probably open a new bug since the symptom is close but the cause may be different due to the context (for me : ganache <-> metamask & FireFox <-> webpage using web3.min.js)

@nazarhussain
Copy link
Contributor

nazarhussain commented Sep 28, 2021

@nicos99 I am pretty confident that problem is somewhere between Genache or Metamask provider. Try your code directly connecting with the local running node. If you can find more insights and share some script without external providers then feel free to re-open this issue.

@nicos99
Copy link
Contributor

nicos99 commented Sep 28, 2021

@nazarhussain ok, I will. However note that it is enough to only change the web3 version to 1.2.9 (with <script src="https://cdn.jsdelivr.net/npm/web3@1.2.9/dist/web3.min.js">) for the js script to catch correctly the revert exception

@jesmith0
Copy link

jesmith0 commented Oct 7, 2021

Same issue here:

Uncaught TypeError: err.data.substring is not a function
      at sendTxCallback (node_modules/web3-core-method/lib/index.js:510:43)
      at Object.callback (node_modules/web3-core-requestmanager/lib/index.js:288:20)
      at /app/node_modules/web3-providers-ws/lib/index.js:114:45
      at Array.forEach (<anonymous>)
      at WebsocketProvider._onMessage (node_modules/web3-providers-ws/lib/index.js:102:69)
      at W3CWebSocket._dispatchEvent [as dispatchEvent] (node_modules/yaeti/lib/EventTarget.js:115:12)
      at W3CWebSocket.onMessage (node_modules/websocket/lib/W3CWebSocket.js:234:14)
      at WebSocketConnection.<anonymous> (node_modules/websocket/lib/W3CWebSocket.js:205:19)
      at WebSocketConnection.processFrame (node_modules/websocket/lib/WebSocketConnection.js:554:26)
      at /app/node_modules/websocket/lib/WebSocketConnection.js:323:40
      at processTicksAndRejections (internal/process/task_queues.js:79:11)

Environment:
Ganache CLI v6.12.2 (ganache-core: 2.13.2)
web3@1.30

No issues when using web3@1.2.9

@ntudor11
Copy link

ntudor11 commented Dec 7, 2021

Bump, still no fix yet the issue has been closed.

/node_modules/web3-core-method/lib/index.js:518
                    reasonData = err.data.substring(10);
                                          ^
TypeError: err.data.substring is not a function

Code at the specified file & line:

else if (err && err.data) {
   reasonData = err.data.substring(10);
}

Where reasonData seems to be an object, not a string.

Web3 version: 1.6.1

@tabakhian
Copy link

tabakhian commented Jan 31, 2022

iam using "https://bsc-dataseed.binance.org/" and get the error on 1.7.0

   Uncaught TypeError: err.data.substring is not a function
at sendTxCallback (index.js?7789:518:1)
at cb (util.js?3022:689:1)
at callbackifyOnRejected (util.js?3022:666:1)
at eval (process.js?4362:5:1)

when i set handleRevert to true metamask goes crazy and make errors every second right after i send the contract method
MetaMask - RPC Error: Internal JSON-RPC error.

mkobelt added a commit to soberm/x-chain-protocols that referenced this issue Mar 21, 2022
@jspruance
Copy link

I am experiencing the same behavior. I see this is now closed - what was the resolution? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug Investigate P2 Medium severity bugs
Projects
None yet
Development

No branches or pull requests