Linting rules
E034: throw-requires-errors-enum
Warns when symbolic throw codes are referenced as bare constants.
Metadata
Code:E034Rule:throw-requires-errors-enumStatus: Stable sincev0.0.1Quick fix: not available
What it does
Warns when symbolic throw codes are referenced as bare constants.
Why is this bad?
Using Errors.SomeName keeps custom exit codes consistent across contracts, tests, and compiler ABI output.
Bare constants such as ERR_NOT_OWNER are harder to discover and produce inconsistent symbolic names.
Example
struct Storage {
ownerAddress: address
}
const ERR_NOT_OWNER = 401
fun onInternalMessage(in: InMessage) {
val storage = lazy Storage.load();
val isOwner = in.senderAddress == storage.ownerAddress;
assert (isOwner) throw ERR_NOT_OWNER;}Use instead:
enum Errors {
NotOwner = 401
}
struct Storage {
ownerAddress: address
}
fun onInternalMessage(in: InMessage) {
val storage = lazy Storage.load();
val isOwner = in.senderAddress == storage.ownerAddress;
assert (isOwner) throw Errors.NotOwner;
}Last updated on