-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.rs
More file actions
103 lines (85 loc) · 2.99 KB
/
errors.rs
File metadata and controls
103 lines (85 loc) · 2.99 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
//! Error types for show command handler
use crate::domain::environment::repository::RepositoryError;
use crate::shared::error::kind::ErrorKind;
use crate::shared::error::traceable::Traceable;
/// Comprehensive error type for the `ShowCommandHandler`
#[derive(Debug, thiserror::Error)]
pub enum ShowCommandHandlerError {
#[error("Environment not found: '{name}'")]
EnvironmentNotFound { name: String },
#[error("Failed to load environment: {0}")]
LoadError(#[from] RepositoryError),
}
impl Traceable for ShowCommandHandlerError {
fn trace_format(&self) -> String {
match self {
Self::EnvironmentNotFound { name } => {
format!("ShowCommandHandlerError: Environment not found - '{name}'")
}
Self::LoadError(e) => {
format!("ShowCommandHandlerError: Failed to load environment - {e}")
}
}
}
fn trace_source(&self) -> Option<&dyn Traceable> {
match self {
Self::EnvironmentNotFound { .. } | Self::LoadError(_) => None,
}
}
fn error_kind(&self) -> ErrorKind {
match self {
Self::EnvironmentNotFound { .. } => ErrorKind::Configuration,
Self::LoadError(_) => ErrorKind::StatePersistence,
}
}
}
impl ShowCommandHandlerError {
/// Provides detailed troubleshooting guidance for this error
///
/// # Example
///
/// ```
/// use torrust_tracker_deployer_lib::application::command_handlers::show::errors::ShowCommandHandlerError;
///
/// let error = ShowCommandHandlerError::EnvironmentNotFound {
/// name: "my-env".to_string(),
/// };
///
/// let help = error.help();
/// assert!(help.contains("Verify the environment name"));
/// ```
#[must_use]
pub fn help(&self) -> &'static str {
match self {
Self::EnvironmentNotFound { .. } => {
"Environment Not Found - Troubleshooting:
1. Verify the environment name is correct
2. Check if the environment was created:
ls data/
3. If the environment doesn't exist, create it first:
cargo run -- create environment --env-file <config.json>
4. If the environment was previously destroyed, the state may have been removed
Common causes:
- Typo in environment name
- Environment was destroyed and state was removed
- Working in the wrong directory
For more information, see docs/user-guide/commands.md"
}
Self::LoadError(_) => {
"Environment Load Error - Troubleshooting:
1. Check if the environment state file exists:
ls data/<env-name>/environment.json
2. Verify the file is valid JSON:
cat data/<env-name>/environment.json | jq .
3. Ensure the file is readable:
ls -la data/<env-name>/environment.json
4. Check for disk space issues or file system errors
Common causes:
- Corrupted environment state file
- Interrupted write operation
- File system permissions issues
For more information, see docs/user-guide/commands.md"
}
}
}
}