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
use flex_error::define_error;

use ibc_relayer_types::core::ics03_connection::connection::Counterparty;
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, ConnectionId, PortId};

use crate::error::Error as RelayerError;
use crate::spawn::SpawnError;
use crate::supervisor::scan::Error as ScanError;

define_error! {
    Error {
        ChannelUninitialized
            {
                port_id: PortId,
                channel_id: ChannelId,
                chain_id: ChainId,
            }
            |e| {
                format_args!("channel {0}/{1} on chain {2} is not open",
                    e.port_id, e.channel_id, e.chain_id)
            },

        ChannelConnectionUninitialized
            {
                channel_id: ChannelId,
                chain_id: ChainId,
                counterparty: Counterparty
            }
            |e| {
                format_args!("channel {} on chain {} has a connection with uninitialized counterparty {:?}",
                    e.channel_id, e.chain_id, e.counterparty)
            },

        ConnectionNotOpen
            {
                connection_id: ConnectionId,
                channel_id: ChannelId,
                chain_id: ChainId,
            }
            |e| {
                format_args!("connection {0} (underlying channel {1}) on chain {2} is not open",
                    e.connection_id, e.channel_id, e.chain_id)
            },

        MissingConnectionHops
            {
                channel_id: ChannelId,
                chain_id: ChainId,
            }
            |e| {
                format_args!("channel {0} on chain {1} has no connection hops specified",
                    e.channel_id, e.chain_id)
            },

        MissingCounterpartyChannelId
            |_| { "failed due to missing counterparty channel id" },

        Relayer
            [ RelayerError ]
            |_| { "relayer error" },

        NoChainsAvailable
            |_| { "supervisor was not able to connect to any chains" },

        Spawn
            [ SpawnError ]
            |_| { "supervisor was not able to spawn chain runtime" },

        Scan
            [ ScanError ]
            |_| { "supervisor encountered an error when scanning chains" },

        HandleSend
            |_| { "failed to send a command to the supervisor through a channel" },

        HandleRecv
            |_| { "failed to receive the result of a command from the supervisor through a channel" },
    }
}

impl Error {
    pub fn log_as_debug(&self) -> bool {
        matches!(self.detail(), ErrorDetail::Spawn(e) if e.source.log_as_debug())
    }
}