use thiserror::Error;
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum SkillError {
#[error("invalid request: {0}")]
InvalidRequest(String),
#[error("internal: {0}")]
Internal(String),
#[error("rejected by {gate}: {reason}")]
Rejected { gate: String, reason: String },
}
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum SinkError {
#[error("sink closed")]
Closed,
#[error("sink backend: {0}")]
Backend(String),
}
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum ManifestError {
#[error("manifest parse error at {location}: {reason}")]
Parse { location: String, reason: String },
#[error("schema validation error at {location}: {reason}")]
Schema { location: String, reason: String },
}
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum RenderError {
#[error("missing template variable `{path}` at offset {offset}")]
MissingVariable { path: String, offset: usize },
#[error("template syntax error at offset {offset}: {reason}")]
Syntax { offset: usize, reason: String },
}
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum ValidationError {
#[error("schema validation failed at {location}: {reason}")]
Invalid { location: String, reason: String },
#[error("unsupported JSON Schema keyword `{keyword}`")]
UnsupportedKeyword { keyword: String },
}
#[cfg(test)]
mod tests {
use super::SkillError;
#[test]
fn skill_error_variant_set_is_fixed() {
fn label(e: &SkillError) -> &'static str {
match e {
SkillError::InvalidRequest(_) => "invalid-request",
SkillError::Internal(_) => "internal",
SkillError::Rejected { .. } => "rejected",
}
}
assert_eq!(
label(&SkillError::InvalidRequest("x".into())),
"invalid-request"
);
assert_eq!(label(&SkillError::Internal("x".into())), "internal");
assert_eq!(
label(&SkillError::Rejected {
gate: "g".into(),
reason: "r".into()
}),
"rejected"
);
}
}