1use 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
33pub fn empty_attribute_key(value: impl Into<String>) -> String {
35 format!("Empty attribute key. Value: {0}", value.into())
36}
37
38pub 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
46pub fn event_type_too_short(ty: impl Into<String>) -> String {
48 format!("Event type too short: {0}", ty.into())
49}
50
51pub fn unsupported_wasm_query(query: WasmQuery) -> String {
53 format!("Unsupported wasm query: {query:?}")
54}
55
56pub fn unsupported_wasm_message(msg: WasmMsg) -> String {
58 format!("Unsupported wasm message: {msg:?}")
59}
60
61pub fn invalid_code_id() -> String {
63 "code id: invalid".to_string()
64}
65
66pub fn unregistered_code_id(code_id: u64) -> String {
68 format!("code id {code_id}: no such code")
69}
70
71pub fn duplicated_code_id(code_id: u64) -> String {
73 format!("duplicated code id {code_id}")
74}
75
76pub fn no_more_code_id_available() -> String {
78 "no more code identifiers available".to_string()
79}
80
81pub fn duplicated_contract_address(addr: impl Into<String>) -> String {
83 format!(
84 "Contract with this address already exists: {0}",
85 addr.into()
86 )
87}