Skip to main content

hindsight/
error.rs

1//! Error types for Claude Hindsight
2//!
3//! Uses `thiserror` for structured error handling following Rust best practices.
4
5use thiserror::Error;
6
7/// Result type alias for Claude Hindsight operations
8pub type Result<T> = std::result::Result<T, HindsightError>;
9
10#[derive(Error, Debug)]
11pub enum HindsightError {
12    #[error("IO error: {0}")]
13    Io(#[from] std::io::Error),
14
15    #[error("JSON parsing error at line {line}: {message}")]
16    JsonParse { line: usize, message: String },
17
18    #[error("Database error: {0}")]
19    Database(#[from] rusqlite::Error),
20
21    #[error("Session not found: {0}")]
22    SessionNotFound(String),
23
24    #[error("Configuration error: {0}")]
25    Config(String),
26
27    #[error("File watcher error: {0}")]
28    FileWatcher(String),
29
30    #[error("No Claude Code sessions found")]
31    NoSessionsFound,
32
33    #[error("Invalid session format: {0}")]
34    InvalidSession(String),
35}
36
37impl From<serde_json::Error> for HindsightError {
38    fn from(err: serde_json::Error) -> Self {
39        HindsightError::JsonParse {
40            line: err.line(),
41            message: err.to_string(),
42        }
43    }
44}