network_protocol/
error.rs1use serde::{Deserialize, Serialize};
40use std::io;
41use thiserror::Error;
42
43#[derive(Error, Debug, Serialize, Deserialize)]
45pub enum ProtocolError {
46 #[error("I/O error: {0}")]
47 #[serde(skip_serializing, skip_deserializing)]
48 Io(#[from] io::Error),
49
50 #[error("Serialization error: {0}")]
51 #[serde(skip_serializing, skip_deserializing)]
52 Serialization(#[from] bincode::Error),
53
54 #[error("Serialize error: {0}")]
55 SerializeError(String),
56
57 #[error("Deserialize error: {0}")]
58 DeserializeError(String),
59
60 #[error("Transport error: {0}")]
61 TransportError(String),
62
63 #[error("Connection closed")]
64 ConnectionClosed,
65
66 #[error("Security error: {0}")]
67 SecurityError(String),
68
69 #[error("Invalid protocol header")]
70 InvalidHeader,
71
72 #[error("Unsupported protocol version: {0}")]
73 UnsupportedVersion(u8),
74
75 #[error("Packet too large: {0} bytes")]
76 OversizedPacket(usize),
77
78 #[error("Decryption failed")]
79 DecryptionFailure,
80
81 #[error("Encryption failed")]
82 EncryptionFailure,
83
84 #[error("Compression failed")]
85 CompressionFailure,
86
87 #[error("Decompression failed")]
88 DecompressionFailure,
89
90 #[error("Handshake failed: {0}")]
91 HandshakeError(String),
92
93 #[error("Unexpected message type")]
94 UnexpectedMessage,
95
96 #[error("Timeout occurred")]
97 Timeout,
98
99 #[error("Connection timed out (no activity)")]
100 ConnectionTimeout,
101
102 #[error("Configuration error: {0}")]
103 ConfigError(String),
104
105 #[error("Custom error: {0}")]
106 Custom(String),
107
108 #[error("TLS error: {0}")]
109 TlsError(String),
110}
111
112pub type Result<T> = std::result::Result<T, ProtocolError>;