1pub use anyhow::{anyhow, bail, Context as AnyContext, Error as AnyError, Result as AnyResult};
4use cosmwasm_std::{WasmMsg, WasmQuery};
5use thiserror::Error;
6
7#[derive(Debug, Error, PartialEq, Eq)]
9pub enum Error {
10 #[error("Empty attribute key. Value: {0}")]
12 EmptyAttributeKey(String),
13
14 #[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("Attribute key starts with reserved prefix _: {0}")]
21 ReservedAttributeKey(String),
22
23 #[error("Event type too short: {0}")]
25 EventTypeTooShort(String),
26
27 #[error("Unsupported wasm query: {0:?}")]
29 UnsupportedWasmQuery(WasmQuery),
30
31 #[error("Unsupported wasm message: {0:?}")]
33 UnsupportedWasmMsg(WasmMsg),
34
35 #[error("code id: invalid")]
37 InvalidCodeId,
38
39 #[error("code id {0}: no such code")]
41 UnregisteredCodeId(u64),
42
43 #[error("duplicated code id {0}")]
45 DuplicatedCodeId(u64),
46
47 #[error("no more code identifiers available")]
49 NoMoreCodeIdAvailable,
50
51 #[error("Contract with this address already exists: {0}")]
53 DuplicatedContractAddress(String),
54}
55
56impl Error {
57 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 pub fn empty_attribute_value(key: impl Into<String>) -> Self {
65 #[allow(deprecated)]
66 Self::EmptyAttributeValue(key.into())
67 }
68
69 pub fn reserved_attribute_key(key: impl Into<String>) -> Self {
71 Self::ReservedAttributeKey(key.into())
72 }
73
74 pub fn event_type_too_short(ty: impl Into<String>) -> Self {
76 Self::EventTypeTooShort(ty.into())
77 }
78
79 pub fn unsupported_wasm_query(query: WasmQuery) -> Self {
81 Self::UnsupportedWasmQuery(query)
82 }
83
84 pub fn unsupported_wasm_message(msg: WasmMsg) -> Self {
86 Self::UnsupportedWasmMsg(msg)
87 }
88
89 pub fn invalid_code_id() -> Self {
91 Self::InvalidCodeId
92 }
93
94 pub fn unregistered_code_id(code_id: u64) -> Self {
96 Self::UnregisteredCodeId(code_id)
97 }
98
99 pub fn duplicated_code_id(code_id: u64) -> Self {
101 Self::DuplicatedCodeId(code_id)
102 }
103
104 pub fn no_more_code_id_available() -> Self {
106 Self::NoMoreCodeIdAvailable
107 }
108
109 pub fn duplicated_contract_address(address: impl Into<String>) -> Self {
111 Self::DuplicatedContractAddress(address.into())
112 }
113}