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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std::io::Error as IoError;

use fluvio::FluvioError;
use fluvio_cluster::{ClusterError, CheckError};

#[derive(thiserror::Error, Debug)]
pub enum CliError {
    #[error(transparent)]
    IoError {
        #[from]
        source: IoError,
    },
    #[error("Fluvio client error")]
    ClientError {
        #[from]
        source: FluvioError,
    },
    #[error("Fluvio cluster error")]
    ClusterError {
        #[from]
        source: ClusterError,
    },
    #[error("Fluvio cluster pre install check error")]
    CheckError {
        #[from]
        source: CheckError,
    },
    #[error("Kubernetes config error")]
    K8ConfigError {
        #[from]
        source: k8_config::ConfigError,
    },
    #[error("Kubernetes client error")]
    K8ClientError {
        #[from]
        source: k8_client::ClientError,
    },
    #[error("Invalid argument: {0}")]
    InvalidArg(String),
    #[error("Package index error")]
    IndexError {
        #[from]
        source: fluvio_index::Error,
    },
    #[error("Error finding executable")]
    WhichError {
        #[from]
        source: which::Error,
    },
    #[error(transparent)]
    HttpError {
        #[from]
        source: HttpError,
    },
    #[error("Unknown error: {0}")]
    Other(String),
}

#[derive(thiserror::Error, Debug)]
#[error("Http Error: {}", inner)]
pub struct HttpError {
    inner: http_types::Error,
}

impl From<http_types::Error> for CliError {
    fn from(e: http_types::Error) -> Self {
        CliError::HttpError {
            source: HttpError { inner: e },
        }
    }
}

impl CliError {
    pub fn invalid_arg<M: Into<String>>(reason: M) -> Self {
        Self::InvalidArg(reason.into())
    }
}