ricecoder_specs/
error.rs

1//! Error types for the specification system
2
3use std::io;
4use thiserror::Error;
5
6/// Errors that can occur in the specification system
7#[derive(Debug, Error)]
8pub enum SpecError {
9    /// Spec not found
10    #[error("Spec not found: {0}")]
11    NotFound(String),
12
13    /// Invalid spec format
14    #[error("Invalid spec format: {0}")]
15    InvalidFormat(String),
16
17    /// Validation failed
18    #[error("Validation failed")]
19    ValidationFailed(Vec<ValidationError>),
20
21    /// Parse error with location information
22    #[error("Parse error at {path}:{line}: {message}")]
23    ParseError {
24        /// File path where error occurred
25        path: String,
26        /// Line number where error occurred
27        line: usize,
28        /// Error message
29        message: String,
30    },
31
32    /// Circular dependency detected
33    #[error("Circular dependency detected: {specs:?}")]
34    CircularDependency {
35        /// Specs involved in the circular dependency
36        specs: Vec<String>,
37    },
38
39    /// Inheritance conflict
40    #[error("Inheritance conflict: {0}")]
41    InheritanceConflict(String),
42
43    /// IO error
44    #[error("IO error: {0}")]
45    IoError(#[from] io::Error),
46
47    /// YAML parsing error
48    #[error("YAML error: {0}")]
49    YamlError(#[from] serde_yaml::Error),
50
51    /// JSON error
52    #[error("JSON error: {0}")]
53    JsonError(#[from] serde_json::Error),
54
55    /// Conversation error
56    #[error("Conversation error: {0}")]
57    ConversationError(String),
58}
59
60/// Validation error with location information
61#[derive(Debug, Clone)]
62pub struct ValidationError {
63    /// File path where error occurred
64    pub path: String,
65    /// Line number where error occurred
66    pub line: usize,
67    /// Column number where error occurred
68    pub column: usize,
69    /// Error message
70    pub message: String,
71    /// Error severity
72    pub severity: Severity,
73}
74
75/// Severity level for validation errors
76#[derive(Debug, Clone, Copy, PartialEq, Eq)]
77pub enum Severity {
78    /// Error - must be fixed
79    Error,
80    /// Warning - should be fixed
81    Warning,
82    /// Info - informational only
83    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}