Skip to main content

vtcode_session_store/
error.rs

1//! Error type for the session store.
2
3use std::path::PathBuf;
4
5/// Errors produced by the session store.
6#[derive(Debug, thiserror::Error)]
7pub enum SessionStoreError {
8    /// IO error while reading or writing a session artifact.
9    #[error("session store IO error at {path}: {source}")]
10    Io {
11        /// Path that triggered the error.
12        path: PathBuf,
13        /// Underlying IO error.
14        source: std::io::Error,
15    },
16
17    /// A JSON (de)serialization error.
18    #[error("session store serialization error: {0}")]
19    Json(#[from] serde_json::Error),
20
21    /// The requested turn does not exist in the index.
22    #[error("turn {turn} not found in session {session}")]
23    TurnNotFound {
24        /// Session id.
25        session: String,
26        /// Missing turn number.
27        turn: u64,
28    },
29
30    /// The store directory could not be created.
31    #[error("failed to create session directory {path}: {source}")]
32    CreateDir {
33        /// Path that could not be created.
34        path: PathBuf,
35        /// Underlying IO error.
36        source: std::io::Error,
37    },
38}
39
40impl SessionStoreError {
41    /// Convenience constructor for an IO error at a path.
42    pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
43        Self::Io {
44            path: path.into(),
45            source,
46        }
47    }
48}