use std::path::PathBuf;
use crate::entry::EntryId;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SessionError {
#[error("I/O error on {path}: {source}")]
Io {
path: PathBuf,
source: std::io::Error,
},
#[error("invalid JSON in {path} line {line}: {source}")]
Json {
path: PathBuf,
line: usize,
source: serde_json::Error,
},
#[error(
"Session id must be non-empty, contain only alphanumeric characters, '-', '_', and '.', and start and end with an alphanumeric character"
)]
InvalidSessionId(String),
#[error("Entry {0} not found")]
UnknownEntry(EntryId),
#[error("session id is ambiguous: {} matches", .0.len())]
AmbiguousId(Vec<PathBuf>),
#[error("unsupported session version {0}")]
UnsupportedVersion(u32),
#[error("Session file is not a valid Oino session: {}", .0.display())]
MissingHeader(PathBuf),
#[error("session header has no cwd: {}", .0.display())]
MissingCwd(PathBuf),
#[error("invalid append: {0}")]
InvalidAppend(&'static str),
#[error("not found: {}", .0.display())]
NotFound(PathBuf),
#[error("operation cancelled")]
Cancelled,
}
#[cfg(feature = "manager")]
#[derive(Debug, thiserror::Error)]
pub enum SessionLockError {
#[error("session is locked by {}", .0.describe())]
HeldBy(crate::manager::LeaseInfo),
#[error("I/O error on {path}: {source}")]
Io {
path: PathBuf,
source: std::io::Error,
},
}
#[cfg(feature = "manager")]
impl SessionError {
pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
Self::Io {
path: path.into(),
source,
}
}
}