//! Error types for erl_iroh. use thiserror::Error; /// Convenient result alias. pub type Result = std::result::Result; /// Top-level error type. #[derive(Debug, Error)] pub enum Error { /// I/O failure on a transport stream. #[error("io error: {0}")] Io(#[from] std::io::Error), /// Erlang distribution handshake failed. #[error("handshake error: {0}")] Handshake(String), /// Distribution message send failed. #[error("send error: {0}")] Send(String), /// Distribution message receive failed. #[error("recv error: {0}")] Recv(String), /// RPC call failed or returned an error term. #[error("rpc error: {0}")] Rpc(String), /// Missing capability (bot power) for the requested operation. #[error("power denied: need {needed}, have {have}")] PowerDenied { /// Required power name. needed: &'static str, /// Powers currently granted. have: String, }, /// Peer / node not found among connected sessions. #[error("node not connected: {0}")] NotConnected(String), /// Invalid node name or endpoint id. #[error("invalid name: {0}")] InvalidName(String), /// iroh endpoint / connection error. #[error("iroh error: {0}")] Iroh(String), /// TLS configuration or handshake error. #[error("tls error: {0}")] Tls(String), /// EPMD lookup failed. #[error("epmd error: {0}")] Epmd(String), /// Session background task stopped. #[error("session terminated")] Terminated, /// Operation timed out. #[error("timeout")] Timeout, /// Catch-all for other failures. #[error(transparent)] Other(#[from] anyhow::Error), } impl Error { pub(crate) fn handshake(e: impl ToString) -> Self { Self::Handshake(e.to_string()) } pub(crate) fn send(e: impl ToString) -> Self { Self::Send(e.to_string()) } pub(crate) fn recv(e: impl ToString) -> Self { Self::Recv(e.to_string()) } pub(crate) fn iroh(e: impl ToString) -> Self { Self::Iroh(e.to_string()) } pub(crate) fn tls(e: impl ToString) -> Self { Self::Tls(e.to_string()) } pub(crate) fn epmd(e: impl ToString) -> Self { Self::Epmd(e.to_string()) } pub(crate) fn rpc(e: impl ToString) -> Self { Self::Rpc(e.to_string()) } }