Skip to main content

devops_models/
error.rs

1//! Unified error type for devops-models.
2//!
3//! # Example
4//!
5//! ```rust
6//! use devops_models::{DevopsError, Result};
7//!
8//! fn parse(yaml: &str) -> Result<serde_json::Value> {
9//!     serde_yaml::from_str(yaml)
10//!         .map_err(|e| DevopsError::YamlParse(e.to_string()))
11//! }
12//! ```
13
14use thiserror::Error;
15
16/// Unified error type for DevOps model operations.
17#[derive(Debug, Error)]
18pub enum DevopsError {
19    /// YAML parsing or deserialization error.
20    #[error("YAML parse error: {0}")]
21    YamlParse(String),
22
23    /// JSON parsing or deserialization error.
24    #[error("JSON parse error: {0}")]
25    JsonParse(String),
26
27    /// Semantic or structural validation failure.
28    #[error("Validation error: {0}")]
29    Validation(String),
30
31    /// LLM API client error.
32    #[error("LLM client error: {0}")]
33    LlmClient(String),
34
35    /// Generic I/O error.
36    #[error("IO error: {0}")]
37    Io(String),
38}
39
40/// Convenience alias for `Result<T, DevopsError>`.
41pub type Result<T> = core::result::Result<T, DevopsError>;
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn error_display() {
49        let e = DevopsError::YamlParse("unexpected token".to_string());
50        assert_eq!(e.to_string(), "YAML parse error: unexpected token");
51    }
52
53    #[test]
54    fn result_alias() {
55        let ok: Result<u32> = Ok(42);
56        assert!(matches!(ok, Ok(42)));
57        let err: Result<u32> = Err(DevopsError::Validation("bad".to_string()));
58        assert!(err.is_err());
59    }
60}