torrust_tracker_deployer_lib/infrastructure/cli_docs/
errors.rs1use thiserror::Error;
6
7#[derive(Debug, Error)]
9pub enum CliDocsGenerationError {
10 #[error("Failed to serialize CLI documentation to JSON")]
12 SerializationFailed {
13 #[source]
15 source: serde_json::Error,
16 },
17}
18
19impl CliDocsGenerationError {
20 #[must_use]
24 pub fn help(&self) -> String {
25 match self {
26 Self::SerializationFailed { .. } => {
27 "CLI documentation serialization failed. This is likely a bug in the documentation generator.\n\
28 \n\
29 What to do:\n\
30 1. Check if the CLI structure is valid\n\
31 2. Verify all metadata can be extracted from Clap\n\
32 3. Report this as a bug if the error persists\n\
33 4. Include the full error message in your bug report"
34 .to_string()
35 }
36 }
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn it_should_provide_help_text_for_serialization_error() {
46 let error = CliDocsGenerationError::SerializationFailed {
47 source: serde_json::Error::io(std::io::Error::other("test")),
48 };
49
50 let help = error.help();
51 assert!(help.contains("What to do:"));
52 assert!(help.contains("bug"));
53 }
54}