1use std::path::PathBuf;
4
5#[derive(Debug, thiserror::Error)]
7pub enum SessionStoreError {
8 #[error("session store IO error at {path}: {source}")]
10 Io {
11 path: PathBuf,
13 source: std::io::Error,
15 },
16
17 #[error("session store serialization error: {0}")]
19 Json(#[from] serde_json::Error),
20
21 #[error("turn {turn} not found in session {session}")]
23 TurnNotFound {
24 session: String,
26 turn: u64,
28 },
29
30 #[error("failed to create session directory {path}: {source}")]
32 CreateDir {
33 path: PathBuf,
35 source: std::io::Error,
37 },
38
39 #[error("invalid audit pack: {0}")]
41 InvalidPack(String),
42
43 #[error(
45 "session {session} is already open in another process; continue there or fork a new session with --session-id <suffix>"
46 )]
47 SessionBusy {
48 session: String,
50 },
51
52 #[error("invalid mail: {0}")]
54 InvalidMail(String),
55
56 #[error("session {session} is not live; messages go to running sessions only")]
58 SessionNotLive {
59 session: String,
61 },
62
63 #[error("session {session} has too many unread messages; it must drain before accepting more")]
65 MailboxFull {
66 session: String,
68 },
69}
70
71impl SessionStoreError {
72 pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
74 Self::Io { path: path.into(), source }
75 }
76
77 pub(crate) fn invalid_mail(reason: impl Into<String>) -> Self {
79 Self::InvalidMail(reason.into())
80 }
81
82 pub(crate) fn session_not_live(session: impl Into<String>) -> Self {
84 Self::SessionNotLive { session: session.into() }
85 }
86
87 pub(crate) fn mailbox_full(session: impl Into<String>) -> Self {
89 Self::MailboxFull { session: session.into() }
90 }
91}