ibc_app_transfer_types/
error.rs

1//! Defines the token transfer error type
2use displaydoc::Display;
3use ibc_core::channel::types::acknowledgement::StatusValue;
4use ibc_core::channel::types::channel::Order;
5use ibc_core::channel::types::error::ChannelError;
6use ibc_core::host::types::error::{DecodingError, HostError};
7use ibc_core::host::types::identifiers::{ChannelId, PortId};
8use ibc_core::primitives::prelude::*;
9
10#[derive(Display, Debug, derive_more::From)]
11pub enum TokenTransferError {
12    /// host error: {0}
13    Host(HostError),
14    /// decoding error: {0}
15    Decoding(DecodingError),
16    /// channel error: {0}
17    Channel(ChannelError),
18    /// missing destination channel `{channel_id}` on port `{port_id}`
19    MissingDestinationChannel {
20        port_id: PortId,
21        channel_id: ChannelId,
22    },
23    /// mismatched channel orders: expected `{expected}`, actual `{actual}`
24    MismatchedChannelOrders { expected: Order, actual: Order },
25    /// mismatched port IDs: expected `{expected}`, actual `{actual}`
26    MismatchedPortIds { expected: PortId, actual: PortId },
27    /// invalid channel state: cannot be closed
28    InvalidClosedChannel,
29    /// failed to deserialize packet data
30    FailedToDeserializePacketData,
31    /// failed to deserialize acknowledgement
32    FailedToDeserializeAck,
33}
34
35#[cfg(feature = "std")]
36impl std::error::Error for TokenTransferError {
37    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
38        match &self {
39            Self::Host(e) => Some(e),
40            Self::Decoding(e) => Some(e),
41            Self::Channel(e) => Some(e),
42            _ => None,
43        }
44    }
45}
46
47impl From<TokenTransferError> for StatusValue {
48    fn from(e: TokenTransferError) -> Self {
49        StatusValue::new(e.to_string()).expect("error message must not be empty")
50    }
51}