1use crate::storage::StorageError;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
10pub enum Error {
11 #[error("Error reading from disk")]
13 ReadDisk(#[source] StorageError),
14 #[error("Error writing to disk")]
16 WriteDisk(#[source] StorageError),
17 #[error("Error flushing the disk")]
19 FlushDisk(#[source] StorageError),
20
21 #[error("{0} is not allocated")]
23 FileInfoNotAllocated(vmgs_format::FileId),
24 #[error("Cannot allocate 0 blocks")]
26 AllocateZero,
27 #[error("Invalid data allocation offsets")]
29 AllocateOffset,
30 #[error("Insufficient resources")]
32 InsufficientResources,
33 #[error("Invalid file ID")]
35 FileId,
36 #[error("Invalid data buffer length")]
38 WriteFileLength,
39 #[error("Trying to allocate too many blocks")]
41 WriteFileBlocks,
42 #[error("Fatal storage initialization error: {0}")]
44 Initialization(#[source] StorageError),
45 #[error("Invalid VMGS file format: {0}")]
47 InvalidFormat(String),
48 #[error("Corrupt VMGS file format: {0}")]
50 CorruptFormat(String),
51 #[error("The VMGS file has a non zero size but the contents are empty")]
53 EmptyFile,
54 #[error("Cannot overwrite encrypted file with plaintext data")]
56 OverwriteEncrypted,
57 #[error("File must be decrypted to perform this operation")]
59 NeedsUnlock,
60 #[error("Failed to use the root key provided to decrypt VMGS metadata key")]
62 DecryptMetadataKey,
63 #[error("VMGS file version does not support encryption")]
65 EncryptionNotSupported,
66 #[error("Cannot perform operation on unencrypted file")]
68 NotEncrypted,
69 #[error("There is no space to add a new encryption key")]
71 DatastoreKeysFull,
72 #[error("Unable to determine inactive key for removal")]
74 NoActiveDatastoreKey,
75 #[error("VMGS is v1 format")]
77 V1Format,
78 #[error("Cannot overwrite file when moving")]
80 OverwriteMove,
81 #[error("Unexpected {0} length: should be {1}, got {2}")]
83 UnexpectedLength(&'static str, usize, usize),
84 #[error("Invalid argument: {0}")]
86 InvalidArgument(&'static str),
87
88 #[cfg(feature = "encryption_ossl")]
90 #[error("OpenSSL error {1}: {0}")]
91 OpenSSL(#[source] openssl::error::ErrorStack, &'static str),
92 #[cfg(all(windows, feature = "encryption_win"))]
94 #[error("BCrypt error {1}: {0}")]
95 BCrypt(#[source] windows_result::Error, &'static str),
96 #[error("Serde JSON error: {0}")]
98 Json(#[from] serde_json::Error),
99}