use fe2o3_amqp_types::definitions::{self};
use tokio::task::JoinError;
use crate::link::LinkRelayError;
#[derive(Debug, thiserror::Error)]
pub(crate) enum SessionStateError {
#[error("Illegal session state")]
IllegalState,
#[error("Connection must have been closed")]
IllegalConnectionState,
#[error("Remote session ended")]
RemoteEnded,
#[error("Remote ended with error")]
RemoteEndedWithError(definitions::Error),
}
#[derive(Debug, thiserror::Error)]
pub enum BeginError {
#[error("Illegal session state")]
IllegalState,
#[error("Connection must have been closed")]
IllegalConnectionState,
#[error("Remote session ended")]
RemoteEnded,
#[error("Remote ended with error")]
RemoteEndedWithError(definitions::Error),
#[error("Local channel-max reached")]
LocalChannelMaxReached,
}
impl From<SessionStateError> for BeginError {
fn from(error: SessionStateError) -> Self {
match error {
SessionStateError::IllegalState => Self::IllegalState,
SessionStateError::IllegalConnectionState => Self::IllegalConnectionState,
SessionStateError::RemoteEnded => Self::RemoteEnded,
SessionStateError::RemoteEndedWithError(err) => Self::RemoteEndedWithError(err),
}
}
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum SessionInnerError {
#[error("A frame (other than attach) was received referencing a handle which is not currently in use of an attached link.")]
UnattachedHandle,
#[error("Remote sent an attach with a name that cannot be found locally")]
RemoteAttachingLinkNameNotFound,
#[error("An attach was received using a handle that is already in use for an attached link.")]
HandleInUse,
#[error("Illegal session state")]
IllegalState,
#[error("Connection must have been closed")]
IllegalConnectionState,
#[error("Found Transfer frame being sent to a Sender")]
TransferFrameToSender,
#[error("Remote session ended")]
RemoteEnded,
#[error("Remote ended with error")]
RemoteEndedWithError(definitions::Error),
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "transaction", feature = "acceptor"))]
#[error("Unknown transaction ID")]
UnknownTxnId,
}
impl From<SessionStateError> for SessionInnerError {
fn from(error: SessionStateError) -> Self {
match error {
SessionStateError::IllegalState => Self::IllegalState,
SessionStateError::IllegalConnectionState => Self::IllegalConnectionState,
SessionStateError::RemoteEnded => Self::RemoteEnded,
SessionStateError::RemoteEndedWithError(err) => Self::RemoteEndedWithError(err),
}
}
}
impl From<LinkRelayError> for SessionInnerError {
fn from(error: LinkRelayError) -> Self {
match error {
LinkRelayError::UnattachedHandle => Self::UnattachedHandle,
LinkRelayError::TransferFrameToSender => Self::TransferFrameToSender,
}
}
}
#[allow(clippy::enum_variant_names)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("A frame (other than attach) was received referencing a handle which is not currently in use of an attached link.")]
UnattachedHandle,
#[error("Remote sent an attach with a name that cannot be found locally")]
RemoteAttachingLinkNameNotFound,
#[error("An attach was received using a handle that is already in use for an attached link.")]
HandleInUse,
#[error("Illegal session state")]
IllegalState,
#[error("Connection must have been closed")]
IllegalConnectionState,
#[error("Found Transfer frame being sent to a Sender")]
TransferFrameToSender,
#[error("Remote session ended")]
RemoteEnded,
#[error("Remote ended with error")]
RemoteEndedWithError(definitions::Error),
#[error(transparent)]
JoinError(#[from] JoinError),
#[cfg(all(feature = "transaction", feature = "acceptor"))]
#[error("Unknown transaction ID")]
UnknownTxnId,
}
impl From<SessionInnerError> for Error {
fn from(error: SessionInnerError) -> Self {
match error {
SessionInnerError::UnattachedHandle => Self::UnattachedHandle,
SessionInnerError::RemoteAttachingLinkNameNotFound => {
Self::RemoteAttachingLinkNameNotFound
}
SessionInnerError::HandleInUse => Self::HandleInUse,
SessionInnerError::IllegalState => Self::IllegalState,
SessionInnerError::IllegalConnectionState => Self::IllegalConnectionState,
SessionInnerError::TransferFrameToSender => Self::TransferFrameToSender,
SessionInnerError::RemoteEnded => Self::RemoteEnded,
SessionInnerError::RemoteEndedWithError(err) => Self::RemoteEndedWithError(err),
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "transaction", feature = "acceptor"))]
SessionInnerError::UnknownTxnId => Self::UnknownTxnId,
}
}
}
impl From<LinkRelayError> for Error {
fn from(error: LinkRelayError) -> Self {
match error {
LinkRelayError::UnattachedHandle => Self::UnattachedHandle,
LinkRelayError::TransferFrameToSender => {
unreachable!("A sender should not receive a transfer frame")
}
}
}
}
impl From<SessionStateError> for Error {
fn from(error: SessionStateError) -> Self {
match error {
SessionStateError::IllegalState => Self::IllegalState,
SessionStateError::IllegalConnectionState => Self::IllegalConnectionState,
SessionStateError::RemoteEnded => Self::RemoteEnded,
SessionStateError::RemoteEndedWithError(err) => Self::RemoteEndedWithError(err),
}
}
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum AllocLinkError {
#[error("Illegal session state")]
IllegalSessionState,
#[error("Link name must be unique")]
DuplicatedLinkName,
}