-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.rs
More file actions
54 lines (48 loc) · 1.64 KB
/
errors.rs
File metadata and controls
54 lines (48 loc) · 1.64 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
//! CLI Documentation Generation Errors
//!
//! Error types for CLI JSON documentation generation failures.
use thiserror::Error;
/// Errors that can occur during CLI documentation generation
#[derive(Debug, Error)]
pub enum CliDocsGenerationError {
/// Failed to serialize documentation to JSON
#[error("Failed to serialize CLI documentation to JSON")]
SerializationFailed {
/// The underlying serialization error
#[source]
source: serde_json::Error,
},
}
impl CliDocsGenerationError {
/// Returns actionable help text for resolving this error
///
/// Following the project's tiered help system pattern.
#[must_use]
pub fn help(&self) -> String {
match self {
Self::SerializationFailed { .. } => {
"CLI documentation serialization failed. This is likely a bug in the documentation generator.\n\
\n\
What to do:\n\
1. Check if the CLI structure is valid\n\
2. Verify all metadata can be extracted from Clap\n\
3. Report this as a bug if the error persists\n\
4. Include the full error message in your bug report"
.to_string()
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_should_provide_help_text_for_serialization_error() {
let error = CliDocsGenerationError::SerializationFailed {
source: serde_json::Error::io(std::io::Error::other("test")),
};
let help = error.help();
assert!(help.contains("What to do:"));
assert!(help.contains("bug"));
}
}