ricecoder_research/
error.rs

1//! Error types for the research system
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Errors that can occur during research operations
7#[derive(Debug, Error)]
8pub enum ResearchError {
9    /// Project not found at the specified path
10    #[error("Project not found at {path}: {reason}")]
11    ProjectNotFound {
12        /// Path where project was expected
13        path: PathBuf,
14        /// Reason why project was not found
15        reason: String,
16    },
17
18    /// Codebase scan failed
19    #[error("Codebase scan failed: {reason}")]
20    ScanFailed {
21        /// Reason for scan failure
22        reason: String,
23    },
24
25    /// Analysis operation failed
26    #[error("Analysis failed: {reason}. Context: {context}")]
27    AnalysisFailed {
28        /// Reason for analysis failure
29        reason: String,
30        /// Additional context about what was being analyzed
31        context: String,
32    },
33
34    /// Dependency parsing failed for a specific language
35    #[error("Dependency parsing failed for {language}: {reason}")]
36    DependencyParsingFailed {
37        /// Programming language that failed to parse
38        language: String,
39        /// Path to the manifest file (stored but not displayed in error message)
40        path: Option<PathBuf>,
41        /// Reason for parsing failure
42        reason: String,
43    },
44
45    /// Semantic index operation failed
46    #[error("Semantic index error: {reason}. Operation: {operation}")]
47    IndexError {
48        /// Reason for index error
49        reason: String,
50        /// Operation that was being performed
51        operation: String,
52    },
53
54    /// Search operation failed
55    #[error("Search failed for query '{query}': {reason}")]
56    SearchFailed {
57        /// The search query that failed
58        query: String,
59        /// Reason for search failure
60        reason: String,
61    },
62
63    /// Cache operation failed
64    #[error("Cache error during {operation}: {reason}")]
65    CacheError {
66        /// Operation being performed (get, set, clear, etc.)
67        operation: String,
68        /// Reason for cache error
69        reason: String,
70    },
71
72    /// IO error with context
73    #[error("IO error: {reason}")]
74    IoError {
75        /// Reason for IO error
76        reason: String,
77    },
78
79    /// Serialization error
80    #[error("Serialization error: {reason}. Format: {format}")]
81    SerializationError {
82        /// Reason for serialization error
83        reason: String,
84        /// Format being serialized (JSON, TOML, YAML, etc.)
85        format: String,
86    },
87
88    /// Invalid configuration
89    #[error("Invalid configuration: {reason}. Expected: {expected}")]
90    InvalidConfiguration {
91        /// Reason why configuration is invalid
92        reason: String,
93        /// What was expected
94        expected: String,
95    },
96}
97
98impl From<serde_json::Error> for ResearchError {
99    fn from(err: serde_json::Error) -> Self {
100        ResearchError::SerializationError {
101            reason: err.to_string(),
102            format: "JSON".to_string(),
103        }
104    }
105}
106
107impl From<toml::de::Error> for ResearchError {
108    fn from(err: toml::de::Error) -> Self {
109        ResearchError::SerializationError {
110            reason: err.to_string(),
111            format: "TOML".to_string(),
112        }
113    }
114}
115
116impl From<serde_yaml::Error> for ResearchError {
117    fn from(err: serde_yaml::Error) -> Self {
118        ResearchError::SerializationError {
119            reason: err.to_string(),
120            format: "YAML".to_string(),
121        }
122    }
123}