Should custom errors be given a bespoke type?

I find it a bit confusing that when defining a custom error like this:

interface MyInterface {
    error MyCustomError();
}

The type of MyInterface.MyCustomError is function() pure.

I know that custom errors are ABI encoded identically as functions, but I think that they deserve a bespoke type.

My vote would go to error, which under the hood would be an alias for bytes24 (just like function).

Where is it reported as function() pure? I wanted to check if we do this by design or if it’s an error but I can’t find this.

I just checked the solc --abi output and I see this:

[{"inputs":[],"name":"MyCustomError","type":"error"}]

In solc --ast-compact-json the error looks like this:

     [
        {
          "errorSelector": "4e7254d6",
          "id": 2,
          "name": "MyCustomError",
          "nameLocation": "34:13:0",
          "nodeType": "ErrorDefinition",
          "parameters":
          {
            "id": 1,
            "nodeType": "ParameterList",
            "parameters": [],
            "src": "47:2:0"
          },
          "src": "28:22:0"
        }
      ]

And in solc --hashes:

Error signatures:
4e7254d6: MyCustomError()

Where is it reported as function() pure ?

I first saw it in a hint in VSCode but this doesn’t look like a problem with the vscode-solidity extension:

When I run the tests with forge, the compiler run fails with the following error:

Error:
   0: Compiler run failed
      TypeError: Explicit type conversion not allowed from "function () pure" to "bytes4".
        --> /path/to/my/test/file.t.sol:33:25:
         |
      33 |         vm.expectRevert(bytes4(MyInterface.MyCustomError));
         |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


   0:

Location:
   cli/src/cmd/utils.rs:43

Environment:

  • solidity v0.8.13+commit.abaa5c0e
  • forge v0.2.0 (a0db055 2022-04-03T00:03:53.441110+00:00)

Oh, so it’s in an error message. True, we should improve that. I suspect that something similar happens when you try it with an event. Can you submit an issue?

1 Like

Can you submit an issue?

I did it! See issue #12896. I would have linked to it but for some reason the forum keeps considering my GitHub links as spam and hiding my posts.

Thanks! I approved your posts and gave you a higher “trust level” so hopefully the false flag issue is resolved now.

1 Like