cw_multi_test/
error.rs

1//! # Error definitions
2
3pub use anyhow::{anyhow, bail, Context as AnyContext, Error as AnyError, Result as AnyResult};
4use cosmwasm_std::{WasmMsg, WasmQuery};
5use thiserror::Error;
6
7/// An enumeration of errors reported across the **CosmWasm MultiTest** library.
8#[derive(Debug, Error, PartialEq, Eq)]
9pub enum Error {
10    /// Error variant for reporting an empty attribute key.
11    #[error("Empty attribute key. Value: {0}")]
12    EmptyAttributeKey(String),
13
14    /// Error variant for reporting an empty attribute value.
15    #[deprecated(note = "This error is not reported anymore. Will be removed in next release.")]
16    #[error("Empty attribute value. Key: {0}")]
17    EmptyAttributeValue(String),
18
19    /// Error variant for reporting a usage of reserved key prefix.
20    #[error("Attribute key starts with reserved prefix _: {0}")]
21    ReservedAttributeKey(String),
22
23    /// Error variant for reporting too short event types.
24    #[error("Event type too short: {0}")]
25    EventTypeTooShort(String),
26
27    /// Error variant for reporting that unsupported wasm query was encountered during processing.
28    #[error("Unsupported wasm query: {0:?}")]
29    UnsupportedWasmQuery(WasmQuery),
30
31    /// Error variant for reporting that unsupported wasm message was encountered during processing.
32    #[error("Unsupported wasm message: {0:?}")]
33    UnsupportedWasmMsg(WasmMsg),
34
35    /// Error variant for reporting invalid contract code.
36    #[error("code id: invalid")]
37    InvalidCodeId,
38
39    /// Error variant for reporting unregistered contract code.
40    #[error("code id {0}: no such code")]
41    UnregisteredCodeId(u64),
42
43    /// Error variant for reporting duplicated contract code identifier.
44    #[error("duplicated code id {0}")]
45    DuplicatedCodeId(u64),
46
47    /// Error variant for reporting a situation when no more contract code identifiers are available.
48    #[error("no more code identifiers available")]
49    NoMoreCodeIdAvailable,
50
51    /// Error variant for reporting duplicated contract addresses.
52    #[error("Contract with this address already exists: {0}")]
53    DuplicatedContractAddress(String),
54}
55
56impl Error {
57    /// Creates an instance of the [Error](Self) for empty attribute key.
58    pub fn empty_attribute_key(value: impl Into<String>) -> Self {
59        Self::EmptyAttributeKey(value.into())
60    }
61
62    #[deprecated(note = "This error is not reported anymore. Will be removed in next release.")]
63    /// Creates an instance of the [Error](Self) for empty attribute value.
64    pub fn empty_attribute_value(key: impl Into<String>) -> Self {
65        #[allow(deprecated)]
66        Self::EmptyAttributeValue(key.into())
67    }
68
69    /// Creates an instance of the [Error](Self) when reserved attribute key was used.
70    pub fn reserved_attribute_key(key: impl Into<String>) -> Self {
71        Self::ReservedAttributeKey(key.into())
72    }
73
74    /// Creates an instance of the [Error](Self) for too short event types.
75    pub fn event_type_too_short(ty: impl Into<String>) -> Self {
76        Self::EventTypeTooShort(ty.into())
77    }
78
79    /// Creates an instance of the [Error](Self) for unsupported wasm queries.
80    pub fn unsupported_wasm_query(query: WasmQuery) -> Self {
81        Self::UnsupportedWasmQuery(query)
82    }
83
84    /// Creates an instance of the [Error](Self) for unsupported wasm messages.
85    pub fn unsupported_wasm_message(msg: WasmMsg) -> Self {
86        Self::UnsupportedWasmMsg(msg)
87    }
88
89    /// Creates an instance of the [Error](Self) for invalid contract code identifier.
90    pub fn invalid_code_id() -> Self {
91        Self::InvalidCodeId
92    }
93
94    /// Creates an instance of the [Error](Self) for unregistered contract code identifier.
95    pub fn unregistered_code_id(code_id: u64) -> Self {
96        Self::UnregisteredCodeId(code_id)
97    }
98
99    /// Creates an instance of the [Error](Self) for duplicated contract code identifier.
100    pub fn duplicated_code_id(code_id: u64) -> Self {
101        Self::DuplicatedCodeId(code_id)
102    }
103
104    /// Creates an instance of the [Error](Self) for exhausted contract code identifiers.
105    pub fn no_more_code_id_available() -> Self {
106        Self::NoMoreCodeIdAvailable
107    }
108
109    /// Creates an instance of the [Error](Self) for duplicated contract addresses.
110    pub fn duplicated_contract_address(address: impl Into<String>) -> Self {
111        Self::DuplicatedContractAddress(address.into())
112    }
113}