1use std::path::PathBuf;
4
5use crate::entry::EntryId;
6
7#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum SessionError {
11 #[error("I/O error on {path}: {source}")]
13 Io {
14 path: PathBuf,
16 source: std::io::Error,
18 },
19 #[error("invalid JSON in {path} line {line}: {source}")]
21 Json {
22 path: PathBuf,
24 line: usize,
26 source: serde_json::Error,
28 },
29 #[error(
31 "Session id must be non-empty, contain only alphanumeric characters, '-', '_', and '.', and start and end with an alphanumeric character"
32 )]
33 InvalidSessionId(String),
34 #[error("Entry {0} not found")]
36 UnknownEntry(EntryId),
37 #[error("session id is ambiguous: {} matches", .0.len())]
39 AmbiguousId(Vec<PathBuf>),
40 #[error("unsupported session version {0}")]
42 UnsupportedVersion(u32),
43 #[error("Session file is not a valid Oino session: {}", .0.display())]
45 MissingHeader(PathBuf),
46 #[error("session header has no cwd: {}", .0.display())]
48 MissingCwd(PathBuf),
49 #[error("invalid append: {0}")]
51 InvalidAppend(&'static str),
52 #[error("not found: {}", .0.display())]
54 NotFound(PathBuf),
55 #[error("operation cancelled")]
57 Cancelled,
58}
59
60#[cfg(feature = "manager")]
62#[derive(Debug, thiserror::Error)]
63pub enum SessionLockError {
64 #[error("session is locked by {}", .0.describe())]
66 HeldBy(crate::manager::LeaseInfo),
67 #[error("I/O error on {path}: {source}")]
69 Io {
70 path: PathBuf,
72 source: std::io::Error,
74 },
75}
76
77#[cfg(feature = "manager")]
78impl SessionError {
79 pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
81 Self::Io {
82 path: path.into(),
83 source,
84 }
85 }
86}