# Should custom errors be given a bespoke type?

**URL:** <https://forum.soliditylang.org/t/should-custom-errors-be-given-a-bespoke-type/935>\
**Category:** Language Design\
**Created:** [April 4, 2022, 1:45pm UTC](https://forum.soliditylang.org/t/should-custom-errors-be-given-a-bespoke-type/935 "2022-04-04T13:45:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulrberg](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/paulrberg/32/537_2.png) [@paulrberg](https://forum.soliditylang.org/u/paulrberg)\
**Post date:** [April 4, 2022, 1:45pm UTC](https://forum.soliditylang.org/t/should-custom-errors-be-given-a-bespoke-type/935/1 "2022-04-04T13:45:21Z")

</div>

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

```auto
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`).

---

<div class="post-metadata">

**Author:** ![cameel](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/cameel/32/34_2.png) [@cameel](https://forum.soliditylang.org/u/cameel)\
**Post date:** [April 4, 2022, 1:53pm UTC](https://forum.soliditylang.org/t/should-custom-errors-be-given-a-bespoke-type/935/2 "2022-04-04T13:53:54Z")

</div>

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:

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

```

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

```auto
     [
        {
          "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`:

```auto
Error signatures:
4e7254d6: MyCustomError()

```

---

<div class="post-metadata">

**Author:** ![paulrberg](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/paulrberg/32/537_2.png) [@paulrberg](https://forum.soliditylang.org/u/paulrberg)\
**Post date:** [April 4, 2022, 2:05pm UTC](https://forum.soliditylang.org/t/should-custom-errors-be-given-a-bespoke-type/935/3 "2022-04-04T14:05:28Z")

</div>

> 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:

 ![Screen Shot 2022-04-04 at 4.57.06 PM](https://us1.discourse-cdn.com/flex001/uploads/solidity1/original/1X/7ec0c9a86e685e28e530e7008ac3f5cd3bafb0d7.png)

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

```solidity
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)

---

<div class="post-metadata">

**Author:** ![cameel](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/cameel/32/34_2.png) [@cameel](https://forum.soliditylang.org/u/cameel)\
**Post date:** [April 4, 2022, 2:20pm UTC](https://forum.soliditylang.org/t/should-custom-errors-be-given-a-bespoke-type/935/4 "2022-04-04T14:20:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paulrberg](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/paulrberg/32/537_2.png) [@paulrberg](https://forum.soliditylang.org/u/paulrberg)\
**Post date:** [April 4, 2022, 2:32pm UTC](https://forum.soliditylang.org/t/should-custom-errors-be-given-a-bespoke-type/935/5 "2022-04-04T14:32:58Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![cameel](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/cameel/32/34_2.png) [@cameel](https://forum.soliditylang.org/u/cameel)\
**Post date:** [April 4, 2022, 2:48pm UTC](https://forum.soliditylang.org/t/should-custom-errors-be-given-a-bespoke-type/935/6 "2022-04-04T14:48:15Z")

</div>

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