Skip to main content

capsule_library/library/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum LibraryError {
5    #[error("library already exists at {0}")]
6    AlreadyExists(std::path::PathBuf),
7
8    #[error("directory is not empty")]
9    DirectoryNotEmpty,
10
11    #[error("corrupt or missing version file: {0}")]
12    CorruptVersion(String),
13
14    #[error("library is locked by PID {pid} on {hostname} (locked at {locked_at})")]
15    Locked {
16        pid: u32,
17        hostname: String,
18        locked_at: i64,
19    },
20
21    #[error("version mismatch: found {found}, expected {expected}")]
22    VersionMismatch { found: u8, expected: u8 },
23
24    /// The catalog (`index/library.sqlite`) was stamped by a newer build than this one.
25    ///
26    /// A refusal, not a downgrade: the catalog is left byte-for-byte untouched and the lock
27    /// is released, because an older binary cannot know what invariants the newer schema
28    /// added. The recovery is to update Capsule (SSoT: Versioning — Client Catalog
29    /// Migration). Typed here rather than flattened into [`Db`](Self::Db) so a client can
30    /// tell the user *which* two versions disagree.
31    #[error(
32        "catalog schema v{found} is newer than this build supports (v{supported}); \
33         update Capsule to open this library"
34    )]
35    CatalogTooNew { found: u32, supported: u32 },
36
37    #[error("I/O error: {0}")]
38    Io(#[from] std::io::Error),
39
40    #[error("database error: {0}")]
41    Db(#[from] rusqlite::Error),
42
43    #[error("CBOR error: {0}")]
44    Cbor(String),
45}