croncat-errors-macro

Crates.iocroncat-errors-macro
lib.rscroncat-errors-macro
version1.0.4
sourcesrc
created_at2023-04-15 21:30:20.707438
updated_at2023-09-25 13:46:34.275063
descriptionProcedural macro meant to annotate a CosmWasm contract's ContractError enum
homepage
repositoryhttps://github.com/CronCats/cw-croncat
max_upload_size
id840200
size4,875
Mykhailo Donchenko (Buckram123)

documentation

README

CronCat errors macro

This package creates a procedural attribute macro that creates #[croncat_error], intended to be placed above the integrating contract's error enum, which is conventionally called ContractError.

Note: this macro should go above the usual Derive we see for this enum. The correct placement looks like this:

#[croncat_error]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
  // variants hereā€¦
}

It will throw a compile-time error if it is not placed correctly.

The macro adds this enum variant:

#[error("CronCat error: {err:?}")]
  CronCatError {
  err: CronCatContractError
}

It also adds this logic:

impl From<CronCatContractError> for ContractError {
  fn from(error: CronCatContractError) -> Self {
    ContractError::CronCatError {
      err: error,
    }
  }
}

The above logic will allow helper functions in croncat-integration-utils to propagate errors in a manner consistent with the contract's errors.

Commit count: 1679

cargo fmt