Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150//! Error types for beamdev.//!//! This module defines the core error types used throughout the crate://! - `ConnectionError` - errors related to node connections//! - `RpcError` - errors from remote procedure calls
use thiserror::Error;
/// Errors that can occur when connecting to or communicating with Erlang nodes.#[derive(Debug, Error)]pub enum ConnectionError { /// The specified node could not be reached. #[error("node '{node}' is unreachable: {reason}")] NodeUnreachable { node: String, reason: String },
/// Authentication failed (wrong cookie). #[error("authentication failed for node '{node}': invalid cookie")] AuthenticationFailed { node: String },
/// The specified node is not connected. #[error("not connected to node '{node}'")] NotConnected { node: String },
/// The handshake with the node failed. #[error("handshake failed with node '{node}': {reason}")] HandshakeFailed { node: String, reason: String },
/// An I/O error occurred. #[error("I/O error: {0}")] Io(#[from] std::io::Error),
/// The connection was lost unexpectedly. #[error("connection lost to node '{node}': {reason}")] ConnectionLost { node: String, reason: String },}
/// Errors that can occur during remote procedure calls.#[derive(Debug, Error)]pub enum RpcError { /// The RPC call timed out. #[error("RPC to {node}:{module}:{function} timed out after {timeout_ms}ms")] Timeout { node: String, module: String, function: String, timeout_ms: u64, },
/// The remote node returned a badrpc error. #[error("bad RPC to {node}:{module}:{function}: {reason}")] BadRpc { node: String, module: String, function: String, reason: String, },
/// The specified node is not connected. #[error("cannot call {module}:{function} - not connected to node '{node}'")] NodeNotConnected { node: String, module: String, function: String, },
/// Failed to encode the RPC arguments. #[error("failed to encode arguments for {module}:{function}: {reason}")] EncodeError { module: String, function: String, reason: String, },
/// Failed to decode the RPC response. #[error("failed to decode response from {module}:{function}: {reason}")] DecodeError { module: String, function: String, reason: String, },
/// The remote node has no such function loaded. #[error("{module}:{function} is not loaded on '{node}'")] Undef { node: String, module: String, function: String, },
/// The evaluated code raised. #[error("evaluation raised {class}: {reason}")] RemoteException { class: String, reason: String },
/// The evaluated code outran its time or memory budget and was killed. #[error("evaluation killed on the node: {reason}")] Killed { reason: String },
/// The node has no Elixir standard library loaded. #[error( "node '{node}' has no Elixir: {module}:{function} is not loaded there. \ Start the node with Elixir on its code path, or evaluate Erlang instead." )] NoElixir { node: String, module: String, function: String, },
/// The remote node answered with a term we do not know how to read. #[error("{message}")] UnexpectedResponse { message: String },
/// The underlying connection encountered an error. #[error("connection error during RPC: {0}")] Connection(#[from] ConnectionError),}
/// Result type alias for connection operations.pub type ConnectionResult<T> = Result<T, ConnectionError>;
/// Result type alias for RPC operations.pub type RpcResult<T> = Result<T, RpcError>;
#[cfg(test)]mod tests { use super::*;
#[test] fn connection_error_display() { let err = ConnectionError::NodeUnreachable { node: "foo@localhost".to_string(), reason: "connection refused".to_string(), }; assert!(err.to_string().contains("foo@localhost")); assert!(err.to_string().contains("unreachable")); }
#[test] fn rpc_error_display() { let err = RpcError::Timeout { node: "bar@localhost".to_string(), module: "erlang".to_string(), function: "node".to_string(), timeout_ms: 5000, }; assert!(err.to_string().contains("bar@localhost")); assert!(err.to_string().contains("timed out")); }}