wireguard_uapi/linux/err/
parse_attribute_error.rs

1use std::num::TryFromIntError;
2use std::string::FromUtf8Error;
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum ParseAttributeError {
7    #[error(
8        "Error parsing Netlink attribute. Expected {} bytes, found {}.",
9        expected,
10        found
11    )]
12    StaticLengthError { expected: usize, found: usize },
13
14    #[error("{0}")]
15    ParseSockAddrError(#[source] ParseSockAddrError),
16
17    #[error("{0}")]
18    ParseIpAddrError(#[source] ParseIpAddrError),
19
20    #[error("{0}")]
21    FromUtf8Error(#[source] FromUtf8Error),
22
23    #[error("{0}")]
24    TryFromIntError(#[source] TryFromIntError),
25
26    #[error("Expected a null-terminated string in Netlink response")]
27    InvalidCStringError,
28}
29
30impl From<FromUtf8Error> for ParseAttributeError {
31    fn from(error: FromUtf8Error) -> Self {
32        ParseAttributeError::FromUtf8Error(error)
33    }
34}
35
36impl From<TryFromIntError> for ParseAttributeError {
37    fn from(error: TryFromIntError) -> Self {
38        ParseAttributeError::TryFromIntError(error)
39    }
40}
41
42#[derive(Error, Debug)]
43pub enum ParseSockAddrError {
44    #[error("Unrecognized address family")]
45    UnrecognizedAddressFamilyError { id: libc::c_int },
46}
47
48impl From<ParseSockAddrError> for ParseAttributeError {
49    fn from(error: ParseSockAddrError) -> Self {
50        ParseAttributeError::ParseSockAddrError(error)
51    }
52}
53
54#[derive(Error, Debug)]
55pub enum ParseIpAddrError {
56    #[error(
57        "Payload does not correspond to known ip address lengths. Found {}.",
58        found
59    )]
60    InvalidIpAddrLengthError { found: usize },
61}
62
63impl From<ParseIpAddrError> for ParseAttributeError {
64    fn from(error: ParseIpAddrError) -> Self {
65        ParseAttributeError::ParseIpAddrError(error)
66    }
67}