1use std::io;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum SpecError {
9 #[error("Spec not found: {0}")]
11 NotFound(String),
12
13 #[error("Invalid spec format: {0}")]
15 InvalidFormat(String),
16
17 #[error("Validation failed")]
19 ValidationFailed(Vec<ValidationError>),
20
21 #[error("Parse error at {path}:{line}: {message}")]
23 ParseError {
24 path: String,
26 line: usize,
28 message: String,
30 },
31
32 #[error("Circular dependency detected: {specs:?}")]
34 CircularDependency {
35 specs: Vec<String>,
37 },
38
39 #[error("Inheritance conflict: {0}")]
41 InheritanceConflict(String),
42
43 #[error("IO error: {0}")]
45 IoError(#[from] io::Error),
46
47 #[error("YAML error: {0}")]
49 YamlError(#[from] serde_yaml::Error),
50
51 #[error("JSON error: {0}")]
53 JsonError(#[from] serde_json::Error),
54
55 #[error("Conversation error: {0}")]
57 ConversationError(String),
58}
59
60#[derive(Debug, Clone)]
62pub struct ValidationError {
63 pub path: String,
65 pub line: usize,
67 pub column: usize,
69 pub message: String,
71 pub severity: Severity,
73}
74
75#[derive(Debug, Clone, Copy, PartialEq, Eq)]
77pub enum Severity {
78 Error,
80 Warning,
82 Info,
84}
85
86impl std::fmt::Display for ValidationError {
87 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88 write!(
89 f,
90 "{:?} at {}:{}:{}: {}",
91 self.severity, self.path, self.line, self.column, self.message
92 )
93 }
94}