Crates.io | croncat-errors-macro |
lib.rs | croncat-errors-macro |
version | 1.0.4 |
source | src |
created_at | 2023-04-15 21:30:20.707438 |
updated_at | 2023-09-25 13:46:34.275063 |
description | Procedural macro meant to annotate a CosmWasm contract's ContractError enum |
homepage | |
repository | https://github.com/CronCats/cw-croncat |
max_upload_size | |
id | 840200 |
size | 4,875 |
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.