Skip to main content

rhaki_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    #[error("Empty attribute value. Key: {0}")]
16    EmptyAttributeValue(String),
17
18    /// Error variant for reporting a usage of reserved key prefix.
19    #[error("Attribute key starts with reserved prefix _: {0}")]
20    ReservedAttributeKey(String),
21
22    /// Error variant for reporting too short event types.
23    #[error("Event type too short: {0}")]
24    EventTypeTooShort(String),
25
26    /// Error variant for reporting that unsupported wasm query was encountered during processing.
27    #[error("Unsupported wasm query: {0:?}")]
28    UnsupportedWasmQuery(WasmQuery),
29
30    /// Error variant for reporting that unsupported wasm message was encountered during processing.
31    #[error("Unsupported wasm message: {0:?}")]
32    UnsupportedWasmMsg(WasmMsg),
33
34    /// Error variant for reporting invalid contract code.
35    #[error("code id: invalid")]
36    InvalidCodeId,
37
38    /// Error variant for reporting unregistered contract code.
39    #[error("code id {0}: no such code")]
40    UnregisteredCodeId(u64),
41
42    /// Error variant for reporting duplicated contract code identifier.
43    #[error("duplicated code id {0}")]
44    DuplicatedCodeId(u64),
45
46    /// Error variant for reporting a situation when no more contract code identifiers are available.
47    #[error("no more code identifiers available")]
48    NoMoreCodeIdAvailable,
49
50    /// Error variant for reporting duplicated contract addresses.
51    #[error("Contract with this address already exists: {0}")]
52    DuplicatedContractAddress(String),
53}
54
55impl Error {
56    /// Creates an instance of the [Error](Self) for empty attribute key.
57    pub fn empty_attribute_key(value: impl Into<String>) -> Self {
58        Self::EmptyAttributeKey(value.into())
59    }
60
61    /// Creates an instance of the [Error](Self) for empty attribute value.
62    pub fn empty_attribute_value(key: impl Into<String>) -> Self {
63        Self::EmptyAttributeValue(key.into())
64    }
65
66    /// Creates an instance of the [Error](Self) when reserved attribute key was used.
67    pub fn reserved_attribute_key(key: impl Into<String>) -> Self {
68        Self::ReservedAttributeKey(key.into())
69    }
70
71    /// Creates an instance of the [Error](Self) for too short event types.
72    pub fn event_type_too_short(ty: impl Into<String>) -> Self {
73        Self::EventTypeTooShort(ty.into())
74    }
75
76    /// Creates an instance of the [Error](Self) for unsupported wasm queries.
77    pub fn unsupported_wasm_query(query: WasmQuery) -> Self {
78        Self::UnsupportedWasmQuery(query)
79    }
80
81    /// Creates an instance of the [Error](Self) for unsupported wasm messages.
82    pub fn unsupported_wasm_message(msg: WasmMsg) -> Self {
83        Self::UnsupportedWasmMsg(msg)
84    }
85
86    /// Creates an instance of the [Error](Self) for invalid contract code identifier.
87    pub fn invalid_code_id() -> Self {
88        Self::InvalidCodeId
89    }
90
91    /// Creates an instance of the [Error](Self) for unregistered contract code identifier.
92    pub fn unregistered_code_id(code_id: u64) -> Self {
93        Self::UnregisteredCodeId(code_id)
94    }
95
96    /// Creates an instance of the [Error](Self) for duplicated contract code identifier.
97    pub fn duplicated_code_id(code_id: u64) -> Self {
98        Self::DuplicatedCodeId(code_id)
99    }
100
101    /// Creates an instance of the [Error](Self) for exhausted contract code identifiers.
102    pub fn no_more_code_id_available() -> Self {
103        Self::NoMoreCodeIdAvailable
104    }
105
106    /// Creates an instance of the [Error](Self) for duplicated contract addresses.
107    pub fn duplicated_contract_address(address: impl Into<String>) -> Self {
108        Self::DuplicatedContractAddress(address.into())
109    }
110}