ai_lib_rust/protocol/
error.rs1#[derive(Debug, thiserror::Error)]
5pub enum ProtocolError {
6 #[error("Failed to load protocol from {path}: {reason}{}", .hint.as_ref().map(|h| format!("\n Hint: {}", h)).unwrap_or_default())]
7 LoadError {
8 path: String,
9 reason: String,
10 hint: Option<String>,
11 },
12
13 #[error("Protocol validation failed: {0}")]
14 ValidationError(String),
15
16 #[error("Schema mismatch: expected {expected}, found {actual} at {path}{}", .hint.as_ref().map(|h| format!("\n Hint: {}", h)).unwrap_or_default())]
17 SchemaMismatch {
18 path: String,
19 expected: String,
20 actual: String,
21 hint: Option<String>,
22 },
23
24 #[error("Protocol not found: {id}{}", .hint.as_ref().map(|h| format!("\n Hint: {}", h)).unwrap_or_default())]
25 NotFound { id: String, hint: Option<String> },
26
27 #[error("Unsupported protocol version '{version}' (max supported: {max_supported}){}", .hint.as_ref().map(|h| format!("\n Hint: {}", h)).unwrap_or_default())]
28 InvalidVersion {
29 version: String,
30 max_supported: String,
31 hint: Option<String>,
32 },
33
34 #[error("Configuration manifest error: {0}")]
35 ManifestError(String),
36
37 #[error("Internal protocol error: {0}")]
38 Internal(String),
39
40 #[error("YAML syntax error: {0}")]
41 YamlError(String),
42}
43
44impl ProtocolError {
45 pub fn with_hint(mut self, hint: impl Into<String>) -> Self {
47 let hint_val = Some(hint.into());
48 match self {
49 ProtocolError::LoadError { ref mut hint, .. } => *hint = hint_val,
50 ProtocolError::SchemaMismatch { ref mut hint, .. } => *hint = hint_val,
51 ProtocolError::NotFound { ref mut hint, .. } => *hint = hint_val,
52 ProtocolError::InvalidVersion { ref mut hint, .. } => *hint = hint_val,
53 _ => (),
54 }
55 self
56 }
57}