aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
blob: baa97cbc8084a7085d183bc5792c5f4e8a4bc754 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{ffi, io, net};

use dhcproto::v4::{MessageType, Opcode};
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
    #[error("empty client id")]
    EmptyClientId,
    #[error("unhandled or unknown message type {0:?}")]
    InvalidMsgType(MessageType),
    #[error("unhandled or unknown opcode {0:?}")]
    InvalidOpcode(Opcode),
    #[error("missing ip address in dhcprequest")]
    NoAddrRequested,
    #[error("missing client id")]
    NoClientId,
    #[error("no ipv4 address on interface {0}")]
    NoIpv4Addr(String),
    #[error("missing message type")]
    NoMsgType,
    #[error("failed to send whole packet (expected {0}, got {1})")]
    PartialSend(usize, usize),
    #[error("address pool exhausted")]
    PoolExhausted,

    #[error("can't parse network address: {0}")]
    AddrParseError(#[from] net::AddrParseError),
    #[error("string contains nul bytes: {0}")]
    Nul(#[from] ffi::NulError),
    #[error("io error: {0}")]
    Io(#[from] io::Error),

    #[error("dhcproto decode error: {0}")]
    DhcprotoDecode(#[from] dhcproto::error::DecodeError),
    #[error("dhcproto encode error: {0}")]
    DhcprotoEncode(#[from] dhcproto::error::EncodeError),
    #[error("netlinklib error: {0}")]
    Netlinklib(#[from] rsdsl_netlinklib::Error),
    #[error("serde_json error: {0}")]
    SerdeJson(#[from] serde_json::Error),
}

pub type Result<T> = std::result::Result<T, Error>;