-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.rs
More file actions
99 lines (90 loc) · 3.41 KB
/
errors.rs
File metadata and controls
99 lines (90 loc) · 3.41 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
//! Validate Command Errors
//!
//! Domain-specific error types for the validate command presentation layer.
use std::path::PathBuf;
use thiserror::Error;
use crate::application::command_handlers::validate::ValidateCommandHandlerError;
use crate::presentation::cli::views::progress::ProgressReporterError;
use crate::presentation::cli::views::ViewRenderError;
/// Errors that can occur during validate command execution
#[derive(Error, Debug)]
pub enum ValidateSubcommandError {
/// Configuration file not found
#[error("Configuration file not found: {path}")]
ConfigFileNotFound {
/// Path to the missing file
path: PathBuf,
},
/// Path exists but is not a file
#[error("Path is not a file: {path}")]
ConfigPathNotFile {
/// Path that is not a file
path: PathBuf,
},
/// File is not readable
#[error("Cannot read configuration file: {path}")]
ConfigFileNotReadable {
/// Path to the unreadable file
path: PathBuf,
},
/// Validation failed (delegated from application layer)
#[error("Validation failed for configuration file: {path}")]
ValidationFailed {
/// Path to the invalid configuration file
path: PathBuf,
/// Underlying application layer error
#[source]
source: ValidateCommandHandlerError,
},
/// Progress reporter error
#[error("Progress display error: {0}")]
ProgressError(String),
/// Output formatting failed (JSON serialization error).
/// This indicates an internal error in data serialization.
#[error(
"Failed to format output: {reason}\nTip: This is a critical bug - please report it with full logs using --log-output file-and-stderr"
)]
OutputFormatting { reason: String },
}
impl ValidateSubcommandError {
/// Provide troubleshooting guidance for the error
///
/// Returns context-sensitive help text to guide users toward resolution.
#[must_use]
pub fn help(&self) -> Option<String> {
match self {
Self::ConfigFileNotFound { path } => Some(format!(
"Verify the file path is correct: {}\n\
Use 'create template' to generate a valid configuration file.",
path.display()
)),
Self::ConfigPathNotFile { path } => Some(format!(
"The path '{}' points to a directory, not a file.\n\
Provide a path to a JSON configuration file.",
path.display()
)),
Self::ConfigFileNotReadable { path } => Some(format!(
"Check file permissions for '{}':\n\
Ensure the file is readable by your user account.",
path.display()
)),
Self::ValidationFailed { source, .. } => Some(source.help()),
Self::ProgressError(_) => None,
Self::OutputFormatting { reason } => Some(format!(
"Output Formatting Failed - Critical Internal Error:\n\nThis is a critical internal error: {reason}\n\nPlease report this bug with full logs.",
)),
}
}
}
impl From<ProgressReporterError> for ValidateSubcommandError {
fn from(err: ProgressReporterError) -> Self {
Self::ProgressError(err.to_string())
}
}
impl From<ViewRenderError> for ValidateSubcommandError {
fn from(e: ViewRenderError) -> Self {
Self::OutputFormatting {
reason: e.to_string(),
}
}
}