Acton
Linting rules

E034: throw-requires-errors-enum

Warns when symbolic throw codes are referenced as bare constants.

Metadata

  • Code: E034
  • Rule: throw-requires-errors-enum
  • Status: Stable since v0.0.1
  • Quick 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;
E034: throw code should use `Errors.<Name>`
}

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;
}
Source code

Last updated on

On this page