1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! # Error definitions

pub use anyhow::{anyhow, bail, Context as AnyContext, Error as AnyError, Result as AnyResult};
use cosmwasm_std::{WasmMsg, WasmQuery};
use thiserror::Error;

/// An enumeration of errors reported across the **CosmWasm MultiTest** library.
#[derive(Debug, Error, PartialEq, Eq)]
pub enum Error {
    /// Error variant for reporting an empty attribute key.
    #[error("Empty attribute key. Value: {0}")]
    EmptyAttributeKey(String),

    /// Error variant for reporting an empty attribute value.
    #[error("Empty attribute value. Key: {0}")]
    EmptyAttributeValue(String),

    /// Error variant for reporting a usage of reserved key prefix.
    #[error("Attribute key starts with reserved prefix _: {0}")]
    ReservedAttributeKey(String),

    /// Error variant for reporting too short event types.
    #[error("Event type too short: {0}")]
    EventTypeTooShort(String),

    /// Error variant for reporting that unsupported wasm query was encountered during processing.
    #[error("Unsupported wasm query: {0:?}")]
    UnsupportedWasmQuery(WasmQuery),

    /// Error variant for reporting that unsupported wasm message was encountered during processing.
    #[error("Unsupported wasm message: {0:?}")]
    UnsupportedWasmMsg(WasmMsg),

    /// Error variant for reporting invalid contract code.
    #[error("code id: invalid")]
    InvalidCodeId,

    /// Error variant for reporting unregistered contract code.
    #[error("code id {0}: no such code")]
    UnregisteredCodeId(u64),

    /// Error variant for reporting duplicated contract code identifier.
    #[error("duplicated code id {0}")]
    DuplicatedCodeId(u64),

    /// Error variant for reporting a situation when no more contract code identifiers are available.
    #[error("no more code identifiers available")]
    NoMoreCodeIdAvailable,

    /// Error variant for reporting duplicated contract addresses.
    #[error("Contract with this address already exists: {0}")]
    DuplicatedContractAddress(String),
}

impl Error {
    /// Creates an instance of the [Error](Self) for empty attribute key.
    pub fn empty_attribute_key(value: impl Into<String>) -> Self {
        Self::EmptyAttributeKey(value.into())
    }

    /// Creates an instance of the [Error](Self) for empty attribute value.
    pub fn empty_attribute_value(key: impl Into<String>) -> Self {
        Self::EmptyAttributeValue(key.into())
    }

    /// Creates an instance of the [Error](Self) when reserved attribute key was used.
    pub fn reserved_attribute_key(key: impl Into<String>) -> Self {
        Self::ReservedAttributeKey(key.into())
    }

    /// Creates an instance of the [Error](Self) for too short event types.
    pub fn event_type_too_short(ty: impl Into<String>) -> Self {
        Self::EventTypeTooShort(ty.into())
    }

    /// Creates an instance of the [Error](Self) for unsupported wasm queries.
    pub fn unsupported_wasm_query(query: WasmQuery) -> Self {
        Self::UnsupportedWasmQuery(query)
    }

    /// Creates an instance of the [Error](Self) for unsupported wasm messages.
    pub fn unsupported_wasm_message(msg: WasmMsg) -> Self {
        Self::UnsupportedWasmMsg(msg)
    }

    /// Creates an instance of the [Error](Self) for invalid contract code identifier.
    pub fn invalid_code_id() -> Self {
        Self::InvalidCodeId
    }

    /// Creates an instance of the [Error](Self) for unregistered contract code identifier.
    pub fn unregistered_code_id(code_id: u64) -> Self {
        Self::UnregisteredCodeId(code_id)
    }

    /// Creates an instance of the [Error](Self) for duplicated contract code identifier.
    pub fn duplicated_code_id(code_id: u64) -> Self {
        Self::DuplicatedCodeId(code_id)
    }

    /// Creates an instance of the [Error](Self) for exhausted contract code identifiers.
    pub fn no_more_code_id_available() -> Self {
        Self::NoMoreCodeIdAvailable
    }

    /// Creates an instance of the [Error](Self) for duplicated contract addresses.
    pub fn duplicated_contract_address(address: impl Into<String>) -> Self {
        Self::DuplicatedContractAddress(address.into())
    }
}