llm_registry_core/
error.rs

1//! Error types for the LLM Registry
2
3use thiserror::Error;
4
5/// Result type alias for Registry operations
6pub type Result<T> = std::result::Result<T, RegistryError>;
7
8/// Main error type for Registry operations
9#[derive(Error, Debug)]
10pub enum RegistryError {
11    /// Asset not found
12    #[error("Asset not found: {0}")]
13    AssetNotFound(String),
14
15    /// Duplicate asset (same name and version)
16    #[error("Duplicate asset: {name} version {version}")]
17    DuplicateAsset { name: String, version: String },
18
19    /// Checksum mismatch
20    #[error("Checksum mismatch: expected {expected}, got {actual}")]
21    ChecksumMismatch { expected: String, actual: String },
22
23    /// Invalid dependency
24    #[error("Invalid dependency: {0}")]
25    InvalidDependency(String),
26
27    /// Circular dependency detected
28    #[error("Circular dependency detected: {0}")]
29    CircularDependency(String),
30
31    /// Policy validation failed
32    #[error("Policy validation failed: {0}")]
33    PolicyValidationFailed(String),
34
35    /// Invalid version format
36    #[error("Invalid version: {0}")]
37    InvalidVersion(String),
38
39    /// Invalid asset type
40    #[error("Invalid asset type: {0}")]
41    InvalidAssetType(String),
42
43    /// Validation error
44    #[error("Validation error: {0}")]
45    ValidationError(String),
46
47    /// Database error (generic)
48    #[error("Database error: {0}")]
49    DatabaseError(String),
50
51    /// Storage error (generic)
52    #[error("Storage error: {0}")]
53    StorageError(String),
54
55    /// Serialization/Deserialization error
56    #[error("Serialization error: {0}")]
57    SerializationError(String),
58
59    /// Authentication error
60    #[error("Authentication failed: {0}")]
61    AuthenticationError(String),
62
63    /// Authorization error
64    #[error("Authorization failed: {0}")]
65    AuthorizationError(String),
66
67    /// Configuration error
68    #[error("Configuration error: {0}")]
69    ConfigurationError(String),
70
71    /// IO error
72    #[error("IO error: {0}")]
73    IoError(String),
74
75    /// Generic internal error
76    #[error("Internal error: {0}")]
77    InternalError(String),
78}
79
80impl From<serde_json::Error> for RegistryError {
81    fn from(err: serde_json::Error) -> Self {
82        RegistryError::SerializationError(err.to_string())
83    }
84}
85
86impl From<semver::Error> for RegistryError {
87    fn from(err: semver::Error) -> Self {
88        RegistryError::InvalidVersion(err.to_string())
89    }
90}