aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
blob: 943b5d24cf53f1f1bc4193b5787ce1f3963b5f23 (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
45
46
47
48
49
50
51
52
53
54
55
56
use std::{ffi, io};

use tokio::sync::{mpsc, watch};
use tokio::task;

use rsdsl_ip_config::{Ipv4Config, Ipv6Config};
use thiserror::Error;

/// An external error that prevents a supervisor from functioning.
#[derive(Debug, Error)]
pub enum Error {
    #[error("got no ipv4 address")]
    NoIpv4Addr,
    #[error("got no ipv4 primary dns")]
    NoIpv4Dns1,
    #[error("got no ipv4 secondary dns")]
    NoIpv4Dns2,
    #[error("got no ipv6 link-local address")]
    NoIpv6Local,
    #[error("got no ipv6 link-local peer address")]
    NoIpv6Remote,
    #[error("no mac address on interface {0}")]
    NoMacAddress(String),
    #[error("no magic number negotiated locally")]
    NoMagicNumber,
    #[error("ipv4 configuration update channel is closed")]
    V4ChannelClosed,
    #[error("ipv6 configuration update channel is closed")]
    V6ChannelClosed,

    #[error("io error: {0}")]
    Io(#[from] io::Error),
    #[error("interface name contains nul byte: {0}")]
    Nul(#[from] ffi::NulError),

    #[error("error joining tokio task: {0}")]
    Join(#[from] task::JoinError),
    #[error("error sending Option<Ipv4Config> to tokio mpsc channel: {0}")]
    MpscSendV4(#[from] mpsc::error::SendError<Option<Ipv4Config>>),
    #[error("error sending Option<Ipv6Config> to tokio mpsc channel: {0}")]
    MpscSendV6(#[from] mpsc::error::SendError<Option<Ipv6Config>>),
    #[error("error receiving from tokio watch channel: {0}")]
    WatchRecv(#[from] watch::error::RecvError),

    #[error("error retrieving local mac address: {0}")]
    MacAddress(#[from] mac_address::MacAddressError),
    #[error("netlinklib error: {0}")]
    Netlinklib(#[from] rsdsl_netlinklib::Error),
    #[error("ppproperly packet (de)serialization failed: {0}")]
    Ppproperly(#[from] ppproperly::Error),
    #[error("serde_json (de)serialization failed: {0}")]
    SerdeJson(#[from] serde_json::Error),
}

/// An alias for a [`std::result::Result`] with the [`enum@Error`] type of this crate.
pub type Result<T> = std::result::Result<T, Error>;