turul_a2a_patterns/
error.rs1use thiserror::Error;
10
11#[non_exhaustive]
14#[derive(Debug, Error)]
15pub enum SkillError {
16 #[error("invalid request: {0}")]
18 InvalidRequest(String),
19 #[error("internal: {0}")]
21 Internal(String),
22 #[error("rejected by {gate}: {reason}")]
26 Rejected { gate: String, reason: String },
27}
28
29#[non_exhaustive]
31#[derive(Debug, Error)]
32pub enum SinkError {
33 #[error("sink closed")]
35 Closed,
36 #[error("sink backend: {0}")]
38 Backend(String),
39}
40
41#[non_exhaustive]
43#[derive(Debug, Error)]
44pub enum ManifestError {
45 #[error("manifest parse error at {location}: {reason}")]
46 Parse { location: String, reason: String },
47 #[error("schema validation error at {location}: {reason}")]
48 Schema { location: String, reason: String },
49}
50
51#[non_exhaustive]
53#[derive(Debug, Error)]
54pub enum RenderError {
55 #[error("missing template variable `{path}` at offset {offset}")]
56 MissingVariable { path: String, offset: usize },
57 #[error("template syntax error at offset {offset}: {reason}")]
58 Syntax { offset: usize, reason: String },
59}
60
61#[non_exhaustive]
63#[derive(Debug, Error)]
64pub enum ValidationError {
65 #[error("schema validation failed at {location}: {reason}")]
66 Invalid { location: String, reason: String },
67 #[error("unsupported JSON Schema keyword `{keyword}`")]
68 UnsupportedKeyword { keyword: String },
69}
70
71#[cfg(test)]
72mod tests {
73 use super::SkillError;
74
75 #[test]
80 fn skill_error_variant_set_is_fixed() {
81 fn label(e: &SkillError) -> &'static str {
82 match e {
83 SkillError::InvalidRequest(_) => "invalid-request",
84 SkillError::Internal(_) => "internal",
85 SkillError::Rejected { .. } => "rejected",
86 }
87 }
88 assert_eq!(
89 label(&SkillError::InvalidRequest("x".into())),
90 "invalid-request"
91 );
92 assert_eq!(label(&SkillError::Internal("x".into())), "internal");
93 assert_eq!(
94 label(&SkillError::Rejected {
95 gate: "g".into(),
96 reason: "r".into()
97 }),
98 "rejected"
99 );
100 }
101}