Allow reverting with signature `error Panic(uint)`
Currently, solidity doesn't allow defining errors with the following names Panic and Error (note: name, not signature).
There are use cases where reverting with this error would be useful.
One example is in library fixed point implementation. When adding two fixed point numbers overflows, then it's useful to revert with Panic(0x11) to be consistent with how the compiler would revert in such cases. (List of error codes, or Docs)
Possible solutions
- @chriseth suggested allowing something like
import Panic from std.errors. - Allow defining errors with signature
Panic(uint)andError(string). - Use inline assembly to mimic the error: no need for the compiler to do anything
- Use a collision hack. Find
<name>(uint)with the same hash asPanic(uint)and similarly forError(string).
Pinging @paulrberg since this could be useful for https://github.com/hifi-finance/prb-math/blob/main/contracts/PRBMath.sol
Yes, this would be helpful. This is the specific place where I am reverting with a custom error that mimics Panic:
if (rValue < x.value) {
revert PRBMathUD60x18__AddOverflow(x.value, y.value);
}
If I could, I would switch to the Panic code instead of using my custom defined error.
Decision: do 1 and 2 at the same time.
Any news on that feature?
Not yet but this is one of the features we have in the priority backlog so it should be one of the first to pick up once we have some more free cycles.
(1) Looks like it depends on stdlib though and that's not ready yet.
Again, any news on that feature?