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
use std::fmt;

use crate::orchestration::{HostIdx, Hostname};

#[allow(dead_code)]
#[derive(Debug, Clone)]
pub(crate) enum OwnershipTransferError {
    HostUnreachable(Hostname),
    UnknownError(),
}

impl fmt::Display for OwnershipTransferError {
    fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::HostUnreachable(h) => f.write_fmt(format_args!("Host {} is unreachable", h)),
            _ => write!(f, "An unknown error occured"),
        }
    }
}

#[derive(Debug, Clone)]
pub(crate) enum InternalError {
    UnknownError(),
}

impl fmt::Display for InternalError {
    fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
        match self {
            _ => write!(f, "An unknown error occured"),
        }
    }
}

#[allow(dead_code)]
#[derive(Debug, Clone)]
pub enum HostManagementError {
    HostAlreadyRegistered(Hostname, HostIdx),
    IndexUnavailable(HostIdx),
    UnknownError(),
}

impl fmt::Display for HostManagementError {
    fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::HostAlreadyRegistered(hostname, host_idx) => f.write_fmt(format_args!(
                "Host '{}' is already registered as ID {}",
                hostname, host_idx,
            )),
            Self::IndexUnavailable(host_idx) => {
                f.write_fmt(format_args!("Host index '{}' cannot be claimed.", host_idx))
            }
            _ => write!(f, "An unknown error occured"),
        }
    }
}