Trying to understand the idiomatic way we should set Errors
in Sui blockchain smart contracts.
From the provided examples it seems that we should define constants per different expected error i.e. in Marketplace smart contract two errors are defined:
// For when amount paid does not match the expected.
const EAmountIncorrect: u64 = 0;
// For when someone tries to delist without ownership.
const ENotOwner: u64 = 1;
Questions:
- what is the idiomatic Move-language way to name the error constants,
starting with the
E
character then camel case? - what if a dev assigns the same number to two or more errors?
That's right.
The author of a Move module is free to assign the same number to more than one errors since they are no different from regular constants. It is up to the consumer of the Move module how to interpret the error codes returned from the Move VM. Sui Move itself doesn't prohibit two error constants from having the same value. We may, however, add a module to Sui stdlib defining an error standard in the future.