APRO-Oracle / apro-ckb-contract

4 stars 0 forks source link

Error should start from non-zero #1

Closed XuJiandong closed 2 months ago

XuJiandong commented 2 months ago

The first error code(IndexOutOfBound) is with value zero: https://github.com/APRO-Oracle/apro-ckb-contract/blob/ed6a352b05ad30809a1656ff73615a97bd2a19cc/contracts/contract/src/common/error.rs#L5

It returns zero as success when IndexOutOfBound occurs: https://github.com/APRO-Oracle/apro-ckb-contract/blob/ed6a352b05ad30809a1656ff73615a97bd2a19cc/contracts/contract/src/main.rs#L36

crypto009 commented 2 months ago

How about adding an item that is never used to occupy errcode 0, like this:

pub enum Error {
    SkipCode0,   // ensure this item would never be used 
    IndexOutOfBound,
    LengthNotEnough,
    ItemMissing,
    ....
}
XuJiandong commented 2 months ago

use this

pub enum Error {
    IndexOutOfBound = 1,
    LengthNotEnough,
    ItemMissing,
    ....
}
crypto009 commented 2 months ago

use this

pub enum Error {
    IndexOutOfBound = 1,
    LengthNotEnough,
    ItemMissing,
    ....
}

Good advice!