Skip to main content

void_core/support/
error.rs

1//! Error types for void-core
2
3use thiserror::Error;
4
5/// Result type for void-core operations
6pub type Result<T> = std::result::Result<T, VoidError>;
7
8/// Errors that can occur in void-core
9#[derive(Debug, Error)]
10pub enum VoidError {
11    #[error("encryption error: {0}")]
12    Encryption(String),
13
14    #[error("decryption error: {0}")]
15    Decryption(String),
16
17    #[error("invalid key: {0}")]
18    InvalidKey(String),
19
20    #[error("invalid cid: {0}")]
21    InvalidCid(String),
22
23    #[error("shard error: {0}")]
24    Shard(String),
25
26    #[error("serialization error: {0}")]
27    Serialization(String),
28
29    #[error("compression error: {0}")]
30    Compression(String),
31
32    #[error("object not found: {0}")]
33    NotFound(String),
34
35    #[error("io error: {0}")]
36    Io(#[from] std::io::Error),
37
38    #[error("repository not initialized")]
39    NotInitialized,
40
41    #[error("repository already exists")]
42    AlreadyExists,
43
44    #[error("invalid branch name: {0}")]
45    InvalidBranchName(String),
46
47    #[error("invalid tag name: {0}")]
48    InvalidTagName(String),
49
50    #[error("invalid HEAD format: {0}")]
51    InvalidHead(String),
52
53    #[error("invalid pattern: {0}")]
54    InvalidPattern(String),
55
56    #[error("repository locked: {0}")]
57    RepoLocked(String),
58
59    #[error("network error: {0}")]
60    Network(String),
61
62    #[error("lock error: {0}")]
63    Lock(String),
64
65    #[error("integrity error: expected {expected}, got {actual}")]
66    IntegrityError { expected: String, actual: String },
67
68    #[error("invalid signature: {0}")]
69    InvalidSignature(String),
70
71    #[error("nothing to commit: {0}")]
72    NothingToCommit(String),
73
74    #[error("data loss guard: commit would delete {deleted_pct}% of files ({parent_files} -> {new_files}). Use --allow-data-loss to override.")]
75    DataLossGuard {
76        parent_files: usize,
77        new_files: usize,
78        deleted_pct: u8,
79    },
80
81    #[error("path traversal blocked: {path} ({reason})")]
82    PathTraversal { path: String, reason: String },
83
84    #[error("configuration error: {0}")]
85    Config(String),
86
87    #[error("unauthorized: {0}")]
88    Unauthorized(String),
89
90    #[error("conflict: {0}")]
91    Conflict(String),
92
93    #[error("invalid path: {0}")]
94    InvalidPath(String),
95}
96
97impl From<void_crypto::CryptoError> for VoidError {
98    fn from(e: void_crypto::CryptoError) -> Self {
99        match e {
100            void_crypto::CryptoError::Encryption(msg) => VoidError::Encryption(msg),
101            void_crypto::CryptoError::Decryption(msg) => VoidError::Decryption(msg),
102            void_crypto::CryptoError::InvalidKey(msg) => VoidError::InvalidKey(msg),
103            void_crypto::CryptoError::Serialization(msg) => VoidError::Serialization(msg),
104            void_crypto::CryptoError::ReadOnlyVault => VoidError::Encryption(e.to_string()),
105        }
106    }
107}