vtcode_memory/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 /// An audit pack is malformed or unsafe (bad schema, path traversal).
40 #[error("invalid audit pack: {0}")]
41 InvalidPack(String),
42}
43
44impl SessionStoreError {
45 /// Convenience constructor for an IO error at a path.
46 pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
47 Self::Io { path: path.into(), source }
48 }
49}