Skip to content

custom error in require statement shows error #8685

@Abbasjafri-syed

Description

@Abbasjafri-syed

try to add custom error in require statement but shows error in foundry:

        error emptyError();

    function requireCustomEmpty() external view {
        require(msg.sender == address(1), emptyError());
    }

this is the test to get error:

   // forge t --mt test_requireCustomEmpty -vvv
    function test_requireCustomEmpty() external {
        (, bytes memory data) = address(contractA).call(abi.encodeWithSignature("requireCustomEmpty()"));
        console.logBytes(data); // return empty data '0x' similar to empty revert
    }

the test shows error:

$ forge t --mt test_requireCustomEmpty -vvv
Compiler run failed:
Error (9322): No matching declaration found after argument-dependent lookup.
  --> src/TryCatch.sol:14:9:
   |
14 |         require(msg.sender == address(1), emptyError());
   |         ^^^^^^^
Note: Candidate: function require(bool)
Note: Candidate: function require(bool, string memory)

Error:
Compilation failed

already added via-ir = true in toml

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions