web3.js
web3.js copied to clipboard
Handle revert enabled, error : web3.eth.handleRevert = true gives error - reason: 'invalid arrayify value', code: 'INVALID_ARGUMENT', argument: 'value'
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected]
for the project I'm working on.
After seting the {handleRevert: true} option on a Contract object, i started reciving the following error that has already been reported here before but was closed without a solution (https://github.com/ChainSafe/web3.js/issues/4079#issue-899831842). I traced the issue back to the line 514 in the react\node_modules\web3-core-method\lib\index.js . There was a function reading the err.data which upon console logging the err showed that there is no revert string under that property. Instead I found the revert reason string inside the err.data.stack property. After that I also fixed the .substring(10) method being called on that data, to .substring(14) to fix the positioning. Also I found no need to execute line 658 with the ( var reason = method.abiCoder.decodeParameter('string', '0x' + reasonData); ) as the revert reason string was a plain string in the err object. So instead I just passed the reason data to the next if block. This would be a minumum changes solution. For my use case I found it usuful to also cut off the details of the stack, and that way just get the revert reason string only as that is what the method (I assume) was initaly meant to do. I achived this by providing the end paramater to .substring of ( err.data.stack.indexOf('at') ) to cut off the stack path before the first line of the stack. I have not had time to extensivly test this, but it worked for me. I just wanted to leave this here as it is something that worked for me and I just could not find any other solution that worked and I belive it is worth investigating. Here is the diff that solved my problem:
diff --git a/node_modules/web3-core-method/lib/index.js b/node_modules/web3-core-method/lib/index.js
index 84cb1c3..5d58686 100644
--- a/node_modules/web3-core-method/lib/index.js
+++ b/node_modules/web3-core-method/lib/index.js
@@ -515,13 +515,13 @@ Method.prototype.buildCall = function () {
reasonData = result.substring(10);
}
else if (err && err.data) {
- reasonData = err.data.substring(10); //changed to err.data.substring and applied different .substring
+ reasonData = err.data.stack.substring(14, err.data.stack.indexOf('at'));
}
+
if (reasonData) {
- var reason = method.abiCoder.decodeParameter('string', '0x' + reasonData); //nothing to decode, revert string is just a plain String
var signature = 'Error(String)';
- utils._fireError(errors.RevertInstructionError(reason, signature), defer.eventEmitter, defer.reject, payload.callback, {
- reason: reason, //changed reason to reasonData in args
+ utils._fireError(errors.RevertInstructionError(reasonData, signature), defer.eventEmitter, defer.reject, payload.callback, {
+ reason: reasonData, //changed the value from reason to reasonData
signature: signature
});
return;
This issue body was partially generated by patch-package.
@DaniloPa8 Thanks for posting this, One of our team member will be looking this, currently our team is focused on web3.js 4.x.
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.