cw_multi_test/
error.rs

1//! # Error definitions
2
3use cosmwasm_std::{WasmMsg, WasmQuery};
4
5macro_rules! std_error_bail {
6    ($msg:literal $(,)?) => {
7        return Err(StdError::msg($msg))
8    };
9    ($err:expr $(,)?) => {
10        return Err(StdError::msg($err))
11    };
12    ($fmt:expr, $($arg:tt)*) => {
13        return Err(StdError::msg(format!($fmt, $($arg)*)))
14    };
15}
16
17pub(crate) use std_error_bail;
18
19macro_rules! std_error {
20    ($msg:literal $(,)?) => {
21        StdError::msg($msg)
22    };
23    ($err:expr $(,)?) => {
24        StdError::msg($err)
25    };
26    ($fmt:expr, $($arg:tt)*) => {
27        StdError::msg(format!($fmt, $($arg)*))
28    };
29}
30
31pub(crate) use std_error;
32
33/// Creates an instance of the error for empty attribute key.
34pub fn empty_attribute_key(value: impl Into<String>) -> String {
35    format!("Empty attribute key. Value: {0}", value.into())
36}
37
38/// Creates an instance of the error when reserved attribute key was used.
39pub fn reserved_attribute_key(key: impl Into<String>) -> String {
40    format!(
41        "Attribute key starts with reserved prefix _: {0}",
42        key.into()
43    )
44}
45
46/// Creates an instance of the error for too short event types.
47pub fn event_type_too_short(ty: impl Into<String>) -> String {
48    format!("Event type too short: {0}", ty.into())
49}
50
51/// Creates an instance of the error for unsupported wasm queries.
52pub fn unsupported_wasm_query(query: WasmQuery) -> String {
53    format!("Unsupported wasm query: {query:?}")
54}
55
56/// Creates an instance of the error for unsupported wasm messages.
57pub fn unsupported_wasm_message(msg: WasmMsg) -> String {
58    format!("Unsupported wasm message: {msg:?}")
59}
60
61/// Creates an instance of the error for invalid contract code identifier.
62pub fn invalid_code_id() -> String {
63    "code id: invalid".to_string()
64}
65
66/// Creates an instance of the error for unregistered contract code identifier.
67pub fn unregistered_code_id(code_id: u64) -> String {
68    format!("code id {code_id}: no such code")
69}
70
71/// Creates an instance of the error for duplicated contract code identifier.
72pub fn duplicated_code_id(code_id: u64) -> String {
73    format!("duplicated code id {code_id}")
74}
75
76/// Creates an instance of the error for exhausted contract code identifiers.
77pub fn no_more_code_id_available() -> String {
78    "no more code identifiers available".to_string()
79}
80
81/// Creates an instance of the error for duplicated contract addresses.
82pub fn duplicated_contract_address(addr: impl Into<String>) -> String {
83    format!(
84        "Contract with this address already exists: {0}",
85        addr.into()
86    )
87}