Skip to main content

torrust_tracker_deployer_lib/infrastructure/cli_docs/
errors.rs

1//! CLI Documentation Generation Errors
2//!
3//! Error types for CLI JSON documentation generation failures.
4
5use thiserror::Error;
6
7/// Errors that can occur during CLI documentation generation
8#[derive(Debug, Error)]
9pub enum CliDocsGenerationError {
10    /// Failed to serialize documentation to JSON
11    #[error("Failed to serialize CLI documentation to JSON")]
12    SerializationFailed {
13        /// The underlying serialization error
14        #[source]
15        source: serde_json::Error,
16    },
17}
18
19impl CliDocsGenerationError {
20    /// Returns actionable help text for resolving this error
21    ///
22    /// Following the project's tiered help system pattern.
23    #[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}