forked from Metaswitch/floki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.rs
More file actions
121 lines (103 loc) · 3.66 KB
/
errors.rs
File metadata and controls
121 lines (103 loc) · 3.66 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/// Error type for floki
use std::fmt;
use std::io;
use std::process::ExitStatus;
/// FlokiSubprocessExitStatus is a structure which wraps an exit status
/// with a process description so we can pretty-print it.
pub struct FlokiSubprocessExitStatus {
pub process_description: String,
pub exit_status: ExitStatus,
}
/// Error types for Floki
#[derive(Debug, Fail)]
pub enum FlokiError {
#[fail(display = "No floki.yaml found in tree")]
ProblemFindingConfigYaml {},
#[fail(display = "Could not normalize the file path '{}': {}", name, error)]
ProblemNormalizingFilePath { name: String, error: io::Error },
#[fail(
display = "There was a problem opening the configuration file '{}': {}",
name, error
)]
ProblemOpeningConfigYaml { name: String, error: io::Error },
#[fail(
display = "There was a problem parsing the configuration file '{}': {}",
name, error
)]
ProblemParsingConfigYaml {
name: String,
error: serde_yaml::Error,
},
#[fail(display = "Running docker command failed with error: {}", error)]
FailedToLaunchDocker { error: io::Error },
#[fail(display = "Failed to complete docker command with error: {}", error)]
FailedToCompleteDockerCommand { error: io::Error },
#[fail(display = "Failed to pull docker image '{}': {}", image, exit_status)]
FailedToPullImage {
image: String,
exit_status: FlokiSubprocessExitStatus,
},
#[fail(display = "Failed to build docker image '{}': {}", image, exit_status)]
FailedToBuildImage {
image: String,
exit_status: FlokiSubprocessExitStatus,
},
#[fail(display = "Failed to check existence of image '{}': {}", image, error)]
FailedToCheckForImage { image: String, error: io::Error },
#[fail(display = "Failed to find the key '{}' in file '{}'", key, file)]
FailedToFindYamlKey { key: String, file: String },
#[fail(display = "Running container failed: {}", exit_status)]
RunContainerFailed {
exit_status: FlokiSubprocessExitStatus,
},
#[fail(display = "Unable to forward ssh socket - cannot find SSH_AUTH_SOCK in environment")]
NoSshAuthSock {},
}
/// Generate a summary string for a process exiting
fn exit_code_diagnosis(exit_status: &ExitStatus) -> String {
match exit_status.code() {
Some(rc) => format!("exited with return code {}", rc),
None => "terminated by a signal".to_string(),
}
}
/// Custom debug formatter for FlokiSubprocessExitStatus
impl fmt::Debug for FlokiSubprocessExitStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{} {}",
self.process_description,
exit_code_diagnosis(&self.exit_status)
)
}
}
/// Custom display formatter for FlokiSubprocessExitStatus
impl fmt::Display for FlokiSubprocessExitStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{} {}",
self.process_description,
exit_code_diagnosis(&self.exit_status)
)
}
}
/// Internal error types for floki - these represent failed assumptions of
/// the developers, and shouldn't actually manifest.
#[derive(Debug, Fail)]
pub enum FlokiInternalError {
#[fail(
display = "An internal assertion failed '{}'. This is probably a bug!",
description
)]
InternalAssertionFailed { description: String },
}
/// Errors made by floki users.
#[derive(Debug, Fail)]
pub enum FlokiUserError {
#[fail(
display = "Invalid verbosity setting of {}. Use a setting between 0 and 3 (-vvv)",
setting
)]
InvalidVerbositySetting { setting: u8 },
}