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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
use crate::core::ics02_client::error as client_error;
use crate::core::ics03_connection::version::Version;
use crate::core::ics24_host::error::ValidationError;
use crate::core::ics24_host::identifier::{ClientId, ConnectionId};
use crate::proofs::ProofError;
use crate::signer::SignerError;
use crate::Height;

use flex_error::define_error;

define_error! {
    #[derive(Debug, PartialEq, Eq)]
    Error {
        Ics02Client
            [ client_error::Error ]
            | _ | { "ics02 client error" },

        InvalidState
            { state: i32 }
            | e | { format_args!("connection state is unknown: {}", e.state) },

        ConnectionExistsAlready
            { connection_id: ConnectionId }
            | e | {
                format_args!("connection exists (was initialized) already: {0}",
                    e.connection_id)
            },

        ConnectionMismatch
            { connection_id: ConnectionId }
            | e | {
                format_args!("connection end for identifier {0} was never initialized",
                    e.connection_id)
            },

        InvalidConsensusHeight
            {
                target_height: Height,
                currrent_height: Height
            }
            | e | {
                format_args!("consensus height claimed by the client on the other party is too advanced: {0} (host chain current height: {1})",
                    e.target_height, e.currrent_height)
            },

        StaleConsensusHeight
            {
                target_height: Height,
                oldest_height: Height
            }
            | e | {
                format_args!("consensus height claimed by the client on the other party has been pruned: {0} (host chain oldest height: {1})",
                    e.target_height, e.oldest_height)
            },

        InvalidIdentifier
            [ ValidationError ]
            | _ | { "identifier error" },

        EmptyProtoConnectionEnd
            | _ | { "ConnectionEnd domain object could not be constructed out of empty proto object" },

        EmptyVersions
            | _ | { "empty supported versions" },

        EmptyFeatures
            | _ | { "empty supported features" },

        NoCommonVersion
            | _ | { "no common version" },

        VersionNotSupported
            {
                version: Version,
            }
            | e | { format_args!("version \"{}\" not supported", e.version) },

        InvalidAddress
            | _ | { "invalid address" },

        MissingProofHeight
            | _ | { "missing proof height" },

        MissingConsensusHeight
            | _ | { "missing consensus height" },

        InvalidProof
            [ ProofError ]
            | _ | { "invalid connection proof" },

        VerifyConnectionState
            [ client_error::Error ]
            | _ | { "error verifying connnection state" },

        Signer
            [ SignerError ]
            | _ | { "invalid signer" },

        ConnectionNotFound
            { connection_id: ConnectionId }
            | e | {
                format_args!("no connection was found for the previous connection id provided {0}",
                    e.connection_id)
            },

        InvalidCounterparty
            | _ | { "invalid signer" },

        ConnectionIdMismatch
            {
                connection_id: ConnectionId,
                counterparty_connection_id: ConnectionId,
            }
            | e | {
                format_args!("counterparty chosen connection id {0} is different than the connection id {1}",
                    e.connection_id, e.counterparty_connection_id)
            },

        MissingCounterparty
            | _ | { "missing counterparty" },


        MissingCounterpartyPrefix
            | _ | { "missing counterparty prefix" },

        NullClientProof
            | _ | { "client proof must be present" },

        FrozenClient
            { client_id: ClientId }
            | e | {
                format_args!("the client id does not match any client state: {0}",
                    e.client_id)
            },

        ConnectionVerificationFailure
            | _ | { "the connection proof verification failed" },

        ConsensusStateVerificationFailure
            { height: Height }
            [ client_error::Error ]
            | e | {
                format_args!("the consensus proof verification failed (height: {0})",
                    e.height)
            },

        // TODO: use more specific error source
        ClientStateVerificationFailure
            {
                client_id: ClientId,
            }
            [ client_error::Error ]
            | e | {
                format_args!("the client state proof verification failed for client id {0}",
                    e.client_id)
            },

        ImplementationSpecific
            | _ | { "implementation specific error" },
    }
}