use plaza::agent::AgentId;
use plaza::error::{PlazaError, SessionError};
use plaza::session::ConnectionId;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum SessionLayerError {
#[error("failed to bind {addr}")]
Bind {
addr: String,
#[source]
source: std::io::Error,
},
#[error("[{transport}] failed to serialize {context}")]
Serialization {
transport: &'static str,
context: &'static str,
#[source]
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("[{transport}] failed to deserialize {context}")]
Deserialization {
transport: &'static str,
context: &'static str,
#[source]
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("[{transport}] could not deliver to connection {conn_id}: {reason}")]
ClientSendFailed {
transport: &'static str,
conn_id: ConnectionId,
reason: &'static str,
},
}
impl<ID: AgentId> From<SessionLayerError> for PlazaError<ID> {
fn from(err: SessionLayerError) -> Self {
match err {
SessionLayerError::Serialization { .. } => PlazaError::Serialization {
message: err.to_string(),
source: None,
},
SessionLayerError::Deserialization { .. } => PlazaError::Deserialization {
message: err.to_string(),
source: None,
},
other => PlazaError::Session(SessionError::TransportError(other.to_string())),
}
}
}