1
votes

Does anybody know why Metamask (only in this case for me) returns an RPC Error in the debugger console while the error is correctly caught by the "try catch" statement inside the Javascript code?

Although the error is caught in console.log(err), Metamask returns an additional RPC Error: (code -32603) in the webconsole (Firefox and Chrome).

I use the Metamask version: 7.7.9 (under ubuntu 18.04 with Truffle 5.1.9, node v13.7.0, npm 6.13.7, Ganache 2.4.0)

My smart contract to reproduce the error is :

pragma solidity >=0.6.0 <0.7.0;

contract userDataBase {

    constructor() public {        
    }

    function getOrderList(
        uint8 _status
        ) 
    public 
    pure
    returns (
        address[] memory,
        uint256[] memory         
        ) 
    {
        uint amount;         
        require(_status >= 0 && _status <= 6);

        amount=0;
        require(amount > 0, "State not includes orders");
        address[] memory userAddr = new address[](amount); 
        uint256[] memory orderIDs = new uint256[](amount);
        return(userAddr, orderIDs); 
    }
}

My Javascript Snippet is:

try {           
  var list = await contract.methods.getOrderList(0).call({from: accountMM});        
 }catch (err) {             
    console.log(err);
}   

the error is correctly caught in console.log(err), but Metamask provides an additional Error:

MetaMask - RPC Error: [object Object] 
{code: -32603, message: "[object Object]", data: {…}, stack: "Error: [object Object]↵    at a (chrome-extension:…eogaeaoehlefnkodbefgpgknn/background.js:1:1208518"}
code: -32603
data: {message: "VM Exception while processing transaction: revert State not includes orders", code: -32000, data: {…}}
message: "[object Object]"
stack: "Error: [object Object]↵    at a (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1188007)↵    at Object.internal (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1188293)↵    at f (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1209307)↵    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1208518"
__proto__: Object
1

1 Answers

0
votes

Have you tried resetting your Metamask? Go to Accounts -> Settings -> Advanced -> Reset Account.

This worked for me as I was also having the same problem before then someone told me to reset the Metamask.