radius_rust/protocol/error.rs
1//! Custom errors that are used in radius-rust crate to notify users of RADIUS specific error
2//! states
3
4
5use thiserror::Error;
6
7// TODO - https://rust-lang.github.io/api-guidelines/naming.html#c-word-order
8#[derive(Debug, Error)]
9/// Represents all errors generated by this library
10pub enum RadiusError {
11 /// Error happens, when Radius Packet fails validation
12 #[error("Verification failed for incoming Radius packet: {error}")]
13 ValidationError {
14 /// Error definition received from crate
15 error: String
16 },
17 /// Error happens, when packet has been badly constructed or got corrupted
18 #[error("Radius packet is malformed: {error}")]
19 MalformedPacketError {
20 /// Error definition received from crate
21 error: String
22 },
23 /// Error happens, when attribute has been badly constructed or got corrupted
24 #[error("Attribute in Radius packet is malformed: {error}")]
25 MalformedAttributeError {
26 /// Error definition received from crate
27 error: String
28 },
29 /// Error happens, when IPv4/IPv6 Address was badly added to Radius Packet or got corrupted
30 /// during packet transmission
31 #[error("Provided IP Address is malformed: {error}")]
32 MalformedIpAddrError {
33 /// Error definition received from crate
34 error: String
35 },
36 /// Error happens, when Interface Id was badly added to Radius Packet or got corrupted during
37 /// packet transmission
38 #[error("Provided Interface Id is malformed: {error}")]
39 MalformedIfIdError {
40 /// Error definition received from crate
41 error: String
42 },
43 /// Error happens, when there is some sort of connection error between sockets, or socket
44 /// cannot bind to the given hostname/port
45 #[error(transparent)]
46 SocketConnectionError(#[from] std::io::Error),
47 /// Error won't happen, but represents the case when socket gets message from unknwon source
48 #[error("Invalid socket connection: {error}")]
49 SocketInvalidConnectionError {
50 /// Error definition received from crate
51 error: String
52 },
53 /// Error happens, when socket cannot parse given hostname/port
54 #[error(transparent)]
55 SocketAddrParseError(#[from] std::net::AddrParseError),
56 /// Error happens, when dictionary file cannot be parsed
57 #[error("Dictionary is malformed or inaccessible")]
58 MalformedDictionaryError {
59 /// Error definition received from crate
60 error: std::io::Error
61 },
62 /// Error happens, when wrong RADIUS Code is supplied
63 #[error("Supplied RADIUS Code is not supported by this library: {error}")]
64 UnsupportedTypeCodeError {
65 /// Error definition received from crate
66 error: String
67 },
68}