3

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?
Kostas Kryptos
  • 4,081
  • 2
  • 23
  • 24

1 Answers1

2

what is the idiomatic Move-language way to name the error constants, starting with the E character then camel case?

That's right.

what if a dev assigns the same number to two or more errors?

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.

emma
  • 36
  • 2
  • Thank you @emma, by "error standard" you imply some enum structure? – Kostas Kryptos Jun 10 '22 at 21:36
  • 1
    I meant something similar to the [Error module in Diem Framework](https://github.com/diem/diem/blob/main/diem-move/diem-framework/move-stdlib/sources/Errors.move), which defines some utility functions for constructing different Diem-specific categories of errors. But we haven't made any decision regarding if we'll add this module or what it will look like. – emma Jun 10 '22 at 21:50