'Revert throws "missing revert data" in inherited method
I've got a base contract which I use to add functionality to other contracts by inheritance.
For some reason, neither revert nor require are working as expected when the method is called by a descendent which acquires the method via "is". eg contract Sample is AttribChecker
Here's part of the method in Attribchecker;
function getAttribute(string memory attribName) public virtual view returns(string memory) {
BindingCollection coll = BindingCollection(_bindingCollectionAddr);
bool attrExists = coll.existsAttrib(attribName);
console.log("attr exists?", attrExists); //works as expected
if (!attrExists) revert("no such attrib"); //when attrExists is true, fails here
[...]
}
Instead of getting a normal revert message, I get this error:
Error: missing revert data in call exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (error={"stackTrace":[{"type":4,"sourceReference":{"function":"getAttribute","contract":"SampleContract","sourceName":"contracts/Embeddable.sol","sourceContent":"//SPDX-License-Identifier: Unlicense\npragma solidity ^0.8.0;\n\nimport \"./BKLibrary.sol\";\nimport \"./BindingCollection.sol\";\nimport \"hardhat/console.sol\";\n\ncontract Embeddable {\n using BKLibrary for string;\n \n bool private _published;\n string private _fqBinding;\n address private _bindingCollectionAddr;\n address private owner;\n\n modifier onlyOwner {\n require(msg.sender==owner, \"onlyOwner\");\n _;\n }\n\n constructor(address bindingColAddress_) (more...)
I would like it to fail with the normal revert message so I can see that it failed because of "no such attrib" not all this other stuff.
Why is it failing with "missing revert data" on the call to revert?
Solution 1:[1]
require takes a boolean, like so:
require(condition, error message);
So your check should look like this:
require(attrExists, "no such attrib");
But your problem is probably with the coll.existsAttrib. From the stack trace, it appears that the revert is caused by an external call. The only external call here is the coll.existsAttrib.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pandapip1 |
