Skip to main content

aivcs_core/domain/
error.rs

1//! Domain-level error taxonomy for AIVCS.
2
3/// Errors produced by event payload validation.
4#[derive(Debug, thiserror::Error)]
5pub enum ValidationError {
6    #[error("unknown event kind: {kind}")]
7    UnknownEventKind { kind: String },
8
9    #[error("event kind {kind} missing required payload field: {field}")]
10    MissingPayloadField { kind: String, field: String },
11
12    #[error("event kind must not be empty")]
13    EmptyKind,
14}
15
16/// AIVCS domain errors.
17#[derive(Debug, thiserror::Error)]
18pub enum AivcsError {
19    #[error("invalid agent spec: {0}")]
20    InvalidAgentSpec(String),
21
22    #[error("invalid CI run spec: {0}")]
23    InvalidCIRunSpec(String),
24
25    #[error("run not found: {0}")]
26    RunNotFound(uuid::Uuid),
27
28    #[error("eval suite not found: {0}")]
29    EvalSuiteNotFound(uuid::Uuid),
30
31    #[error("release conflict: {0}")]
32    ReleaseConflict(String),
33
34    #[error("digest mismatch: expected {expected}, got {actual}")]
35    DigestMismatch { expected: String, actual: String },
36
37    #[error("git error: {0}")]
38    GitError(String),
39
40    #[error("serialization error: {0}")]
41    Serialization(#[from] serde_json::Error),
42
43    #[error("storage error: {0}")]
44    StorageError(String),
45
46    #[error("validation error: {0}")]
47    Validation(#[from] ValidationError),
48
49    #[error("memory error: {0}")]
50    Memory(String),
51
52    #[error("io error: {0}")]
53    Io(#[from] std::io::Error),
54
55    #[error("multi-repo error: {0}")]
56    MultiRepo(String),
57}
58
59/// Result type for AIVCS domain operations.
60pub type Result<T> = std::result::Result<T, AivcsError>;
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_aivcs_error_display() {
68        let err = AivcsError::InvalidAgentSpec("missing git_sha".to_string());
69        assert!(err.to_string().contains("invalid agent spec"));
70
71        let err = AivcsError::InvalidCIRunSpec("stages cannot be empty".to_string());
72        assert!(err.to_string().contains("invalid CI run spec"));
73
74        let id = uuid::Uuid::new_v4();
75        let err = AivcsError::RunNotFound(id);
76        assert!(err.to_string().contains("run not found"));
77    }
78
79    #[test]
80    fn test_digest_mismatch_error() {
81        let err = AivcsError::DigestMismatch {
82            expected: "abc123".to_string(),
83            actual: "def456".to_string(),
84        };
85        let msg = err.to_string();
86        assert!(msg.contains("abc123"));
87        assert!(msg.contains("def456"));
88    }
89
90    #[test]
91    fn test_storage_error() {
92        let err = AivcsError::StorageError("database connection failed".to_string());
93        assert!(err.to_string().contains("storage error"));
94        assert!(err.to_string().contains("database connection failed"));
95    }
96}