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