Skip to main content

hyperi_rustlib/directory_config/
error.rs

1// Project:   hyperi-rustlib
2// File:      src/directory_config/error.rs
3// Purpose:   Error types for DirectoryConfigStore
4// Language:  Rust
5//
6// License:   FSL-1.1-ALv2
7// Copyright: (c) 2026 HYPERI PTY LIMITED
8
9use thiserror::Error;
10
11/// Errors from directory config store operations.
12#[derive(Debug, Error)]
13pub enum DirectoryConfigError {
14    /// Invalid table name (path traversal, backslash, etc.).
15    #[error("invalid table name: {0}")]
16    InvalidTableName(String),
17
18    /// Store has not been started.
19    #[error("store not started")]
20    NotStarted,
21
22    /// Store is already running.
23    #[error("store already running")]
24    AlreadyRunning,
25
26    /// Table (YAML file) not found.
27    #[error("table not found: {0}")]
28    TableNotFound(String),
29
30    /// Key not found within a table.
31    #[error("key '{key}' not found in table '{table}'")]
32    KeyNotFound { table: String, key: String },
33
34    /// Table already exists (on create).
35    #[error("table already exists: {0}")]
36    TableExists(String),
37
38    /// Store is read-only, writes not permitted.
39    #[error("store is read-only")]
40    ReadOnly,
41
42    /// YAML parse error.
43    #[error("YAML parse error in '{file}': {message}")]
44    ParseError { file: String, message: String },
45
46    /// YAML serialisation error.
47    #[error("YAML serialisation error: {0}")]
48    SerializationError(String),
49
50    /// I/O error.
51    #[error("I/O error: {0}")]
52    IoError(#[from] std::io::Error),
53
54    /// Directory does not exist or is not a directory.
55    #[error("directory not found: {0}")]
56    DirectoryNotFound(String),
57
58    /// Git operation failed.
59    #[cfg(feature = "directory-config-git")]
60    #[error("git error: {0}")]
61    GitError(String),
62
63    /// Git not available but git operation requested.
64    #[error("not a git repository")]
65    NotGitRepo,
66}
67
68/// Result type alias for directory config operations.
69pub type DirectoryConfigResult<T> = Result<T, DirectoryConfigError>;