Skip to main content

synwire_storage/
error.rs

1//! Error types for the storage layer.
2
3use thiserror::Error;
4
5/// Errors produced by the storage subsystem.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum StorageError {
9    /// An I/O error occurred while accessing the filesystem.
10    #[error("I/O error: {0}")]
11    Io(#[from] std::io::Error),
12
13    /// A JSON serialisation or deserialisation error.
14    #[error("JSON error: {0}")]
15    Json(#[from] serde_json::Error),
16
17    /// A `SQLite` error.
18    #[error("SQLite error: {0}")]
19    Sqlite(#[from] rusqlite::Error),
20
21    /// The Git first-commit hash could not be determined.
22    #[error("Cannot determine Git first commit: {0}")]
23    GitFirstCommit(String),
24
25    /// A migration step failed.
26    #[error("Migration failed (version {from} → {to}): {reason}")]
27    Migration {
28        /// Source schema version.
29        from: u32,
30        /// Target schema version.
31        to: u32,
32        /// Human-readable reason for the failure.
33        reason: String,
34    },
35
36    /// The storage directory is not writable.
37    #[error("Storage directory not writable: {path}")]
38    NotWritable {
39        /// Path that could not be written.
40        path: String,
41    },
42
43    /// The config file is invalid.
44    #[error("Invalid config at {path}: {reason}")]
45    InvalidConfig {
46        /// Path to the config file.
47        path: String,
48        /// Human-readable reason.
49        reason: String,
50    },
51
52    /// An environment variable could not be read.
53    #[error("Env var error: {0}")]
54    Env(#[from] std::env::VarError),
55}