use std::fmt; use thiserror::Error; #[derive(Error, Debug)] pub enum GurtError { #[error("IO error: {0}")] Io(#[from] std::io::Error), #[error("Serialization error: {0}")] Serialization(#[from] serde_json::Error), #[error("Cryptographic error: {0}")] Crypto(String), #[error("Protocol error: {0}")] Protocol(String), #[error("Invalid message format: {0}")] InvalidMessage(String), #[error("Connection error: {0}")] Connection(String), #[error("Handshake failed: {0}")] Handshake(String), #[error("Timeout error: {0}")] Timeout(String), #[error("Server error: {status} {message}")] Server { status: u16, message: String }, #[error("Client error: {0}")] Client(String), #[error("Cancelled")] Cancelled, } pub type Result = std::result::Result; impl GurtError { pub fn crypto(msg: T) -> Self { GurtError::Crypto(msg.to_string()) } pub fn protocol(msg: T) -> Self { GurtError::Protocol(msg.to_string()) } pub fn invalid_message(msg: T) -> Self { GurtError::InvalidMessage(msg.to_string()) } pub fn connection(msg: T) -> Self { GurtError::Connection(msg.to_string()) } pub fn handshake(msg: T) -> Self { GurtError::Handshake(msg.to_string()) } pub fn timeout(msg: T) -> Self { GurtError::Timeout(msg.to_string()) } pub fn server(status: u16, message: String) -> Self { GurtError::Server { status, message } } pub fn client(msg: T) -> Self { GurtError::Client(msg.to_string()) } }