clone_cw_multi_test/
error.rs

1pub use anyhow::{anyhow, bail, Context as AnyContext, Error as AnyError, Result as AnyResult};
2use cosmwasm_std::{WasmMsg, WasmQuery};
3use thiserror::Error;
4
5#[derive(Debug, Error, PartialEq, Eq)]
6pub enum Error {
7    #[error("Empty attribute key. Value: {value}")]
8    EmptyAttributeKey { value: String },
9
10    #[error("Empty attribute value. Key: {key}")]
11    EmptyAttributeValue { key: String },
12
13    #[error("Attribute key starts with reserved prefix _: {0}")]
14    ReservedAttributeKey(String),
15
16    #[error("Event type too short: {0}")]
17    EventTypeTooShort(String),
18
19    #[error("Unsupported wasm query: {0:?}")]
20    UnsupportedWasmQuery(WasmQuery),
21
22    #[error("Unsupported wasm message: {0:?}")]
23    UnsupportedWasmMsg(WasmMsg),
24
25    #[error("code id: invalid")]
26    InvalidCodeId,
27
28    #[error("code id {0}: no such code")]
29    UnregisteredCodeId(u64),
30
31    #[error("Contract with this address already exists: {0}")]
32    DuplicatedContractAddress(String),
33
34    #[error("Unregistered contract address, not present locally or on-chain")]
35    UnregisteredContractAddress(String),
36}
37
38impl Error {
39    pub fn empty_attribute_key(value: impl Into<String>) -> Self {
40        Self::EmptyAttributeKey {
41            value: value.into(),
42        }
43    }
44
45    pub fn empty_attribute_value(key: impl Into<String>) -> Self {
46        Self::EmptyAttributeValue { key: key.into() }
47    }
48
49    pub fn reserved_attribute_key(key: impl Into<String>) -> Self {
50        Self::ReservedAttributeKey(key.into())
51    }
52
53    pub fn event_type_too_short(ty: impl Into<String>) -> Self {
54        Self::EventTypeTooShort(ty.into())
55    }
56
57    pub fn duplicated_contract_address(address: impl Into<String>) -> Self {
58        Self::DuplicatedContractAddress(address.into())
59    }
60}