Skip to main content

talos_session/
error.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4use uuid::Uuid;
5
6/// Errors that can occur during session operations.
7#[derive(Debug, Error)]
8pub enum SessionError {
9    /// An I/O error occurred (file read/write, directory creation, etc.).
10    #[error("I/O error: {0}")]
11    IoError(#[from] std::io::Error),
12
13    /// Removing one artifact from a Session-owned artifact set failed.
14    #[error(
15        "failed to remove session artifact {path}: {source}; removed={removed:?}; remaining={remaining:?}; retryable=true"
16    )]
17    ArtifactCleanup {
18        /// Exact artifact path whose removal failed.
19        path: PathBuf,
20        /// Underlying filesystem failure.
21        #[source]
22        source: std::io::Error,
23        /// Paths already removed before the failure.
24        removed: Vec<PathBuf>,
25        /// Paths still present and safe to retry.
26        remaining: Vec<PathBuf>,
27    },
28
29    /// Session index cleanup failed while the transcript remained discoverable.
30    #[error("failed to remove Session {session_id} from the index: {message}")]
31    IndexCleanup {
32        /// Session whose supplementary index/fork rows could not be removed.
33        session_id: Uuid,
34        /// Content-free index diagnostic.
35        message: String,
36    },
37
38    /// Orphan-sidecar validation or SQLite ownership probing failed.
39    #[error("failed to reconcile orphan Session sidecar {path}: {message}")]
40    OrphanReconciliation {
41        /// Exact validated sidecar path.
42        path: PathBuf,
43        /// Content-free validation or SQLite diagnostic.
44        message: String,
45    },
46
47    /// A line in the JSONL file is not valid JSON.
48    #[error("invalid JSON in session file: {0}")]
49    InvalidJson(String),
50
51    /// The requested session was not found.
52    #[error("session not found: {0}")]
53    SessionNotFound(Uuid),
54
55    /// The requested entry ID was not found in the session.
56    #[error("entry not found: {0}")]
57    EntryNotFound(String),
58
59    /// The requested branch ID was not found.
60    #[error("branch not found: {0}")]
61    BranchNotFound(String),
62
63    /// Failed to parse a session file.
64    #[error("failed to parse session file: {0}")]
65    ParseError(String),
66
67    /// A per-session internal mutex was poisoned by a panicking thread.
68    #[error("session lock poisoned")]
69    LockPoisoned,
70
71    /// A host-provided external session identifier is invalid.
72    #[error("invalid external session identifier: {0}")]
73    InvalidExternalId(String),
74
75    /// A durable turn cannot be committed because its persisted state is inconsistent.
76    #[error("durable turn error: {0}")]
77    DurableTurn(String),
78
79    /// A turn was already finalized with a different outcome or payload.
80    #[error("durable turn conflict for {turn_id}: existing={existing}, requested={requested}")]
81    DurableTurnConflict {
82        /// Turn identity whose terminal record already exists.
83        turn_id: String,
84        /// Previously persisted terminal outcome or ambiguous state.
85        existing: String,
86        /// Requested terminal outcome.
87        requested: String,
88    },
89}