-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkind.rs
More file actions
122 lines (106 loc) · 3.82 KB
/
Copy pathkind.rs
File metadata and controls
122 lines (106 loc) · 3.82 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
122
//! Generic error kind classification
//!
//! Provides high-level categorization of errors across all commands for
//! debugging and potential recovery strategies. Error kinds appear in trace
//! files and failure contexts but are not directly user-facing.
use serde::{Deserialize, Serialize};
/// Generic error categories for command failures
///
/// These categories provide high-level classification for debugging
/// and potential recovery strategies. They are used in trace files
/// and failure context but are not directly user-facing.
///
/// Error kinds were introduced to provide an easy way to understand
/// what type of error occurred without parsing detailed trace log files.
/// They serve as a high-level summary that can be:
///
/// - Displayed to users without technical details
/// - Used for filtering/grouping errors
/// - Foundation for future retry/recovery strategies based on error category
///
/// # Examples
///
/// ```
/// use torrust_tracker_deployer_lib::shared::ErrorKind;
///
/// let kind = ErrorKind::TemplateRendering;
/// assert_eq!(format!("{kind:?}"), "TemplateRendering");
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ErrorKind {
/// Template rendering or generation failed
///
/// Examples: Tera template errors, invalid template variables,
/// missing template files
TemplateRendering,
/// Infrastructure operations failed
///
/// Examples: `OpenTofu` operations (init, plan, apply), LXD operations,
/// container/VM management failures
InfrastructureOperation,
/// Network connectivity or communication failed
///
/// Examples: SSH connection timeouts, unreachable hosts,
/// network configuration issues
NetworkConnectivity,
/// External tool or command execution failed
///
/// Examples: Ansible playbook failures, shell command errors,
/// tool installation failures
CommandExecution,
/// Timeout or deadline exceeded
///
/// Examples: Operation timeouts, cloud-init wait exceeded,
/// long-running process killed
Timeout,
/// File system or I/O operation failed
///
/// Examples: File read/write errors, permission denied,
/// disk space issues, path not found
FileSystem,
/// Configuration validation or parsing failed
///
/// Examples: Invalid YAML/TOML, missing required fields,
/// configuration value out of range
Configuration,
/// State persistence operation failed
///
/// Examples: Failed to save environment state, repository errors,
/// serialization/deserialization failures, storage access issues
StatePersistence,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_should_serialize_error_kind_to_json() {
let kind = ErrorKind::TemplateRendering;
let json = serde_json::to_string(&kind).unwrap();
assert_eq!(json, "\"TemplateRendering\"");
}
#[test]
fn it_should_deserialize_error_kind_from_json() {
let json = "\"NetworkConnectivity\"";
let kind: ErrorKind = serde_json::from_str(json).unwrap();
assert_eq!(kind, ErrorKind::NetworkConnectivity);
}
#[test]
fn it_should_be_copy_and_clone() {
let kind1 = ErrorKind::CommandExecution;
let kind2 = kind1; // Copy
let kind3 = kind1; // Copy (no need for .clone() on Copy types)
assert_eq!(kind1, kind2);
assert_eq!(kind1, kind3);
}
#[test]
fn it_should_support_equality_comparison() {
assert_eq!(ErrorKind::Timeout, ErrorKind::Timeout);
assert_ne!(ErrorKind::Timeout, ErrorKind::FileSystem);
}
#[test]
fn it_should_have_descriptive_debug_output() {
let kind = ErrorKind::InfrastructureOperation;
let debug_output = format!("{kind:?}");
assert_eq!(debug_output, "InfrastructureOperation");
}
}