vmgs/
error.rs

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