Hi Andrew (@abcoathup),
It’s been a while since I’ve been on the forum. I trust that you are well and you’re enjoying the Australian summer.
I have been working on error handling recently using the event emitter. If I call a function directly from a contract (using contract.methods.myMethod().send{from: Ganache supplied account}) with an input that violates a require statement, then the .error part of the event emitter is invoked. That works as I would expect.
However, if I call a function through a proxy contract with an input that violates a require statement, the .error part of the event emitter is not invoked. I would note that the ‘transactionHash’, 'receipt, and ‘confirmation’ events of the event emitter work when going through proxy contracts. However, I do receive a notification of an error through the console even though I do not have any console.log() statements in my code. See below:
web3.min.js:20 Uncaught (in promise) Error: Returned error: VM Exception while processing transaction: revert Number of offices can't be less than one
at Object.ErrorResponse (web3.min.js:20)
at Object.callback (web3.min.js:20)
at web3.min.js:30
at Array.forEach (<anonymous>)
at s._onMessage (web3.min.js:30)
ErrorResponse @ web3.min.js:20
(anonymous) @ web3.min.js:20
(anonymous) @ web3.min.js:30
s._onMessage @ web3.min.js:30
async function (async)
initializeElectionProxy @ playing.js:743
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
I tried to encapsulate my function call in try catch blocks, but that didn’t do anything.
So, my problem is that I need capture the error information in my javascript code and not just have it displayed in the console. My understanding is that when the transaction reverts due to failing the condition in the require statement, the Yul delegatecall command in the proxy contract returns a ‘0’ which, through a switch statement, calls for a Yul revert command. This Yul revert command, in addition to ending execution and reverting state variables, also returns the failure data which occupies the memory that the normal return data would have occupied.
So, the error information is being returned by the proxy contract. However, it’s not happening in the same way that normal return data would be returned. I set up a test function that returned data and it didn’t simply appear in my console. So, there is some mechanism, outside of the proxy contract, that I don’t understand that is taking the returned error information and logging it to the console.
Do you know anything about this topic? Does the error logged to the console copied earlier in the post mean anything to you? How can I capture the error information when using proxy contracts?
I would appreciate any advice or insight. Cheers.
Sincerely,
Craig