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)]
10#[non_exhaustive]
11pub enum Error {
12    /// Error reading from disk.
13    #[error("read disk error")]
14    ReadDisk(#[source] StorageError),
15    /// Error writing to disk.
16    #[error("write disk error")]
17    WriteDisk(#[source] StorageError),
18    /// Error flushing the disk.
19    #[error("flush disk error")]
20    FlushDisk(#[source] StorageError),
21
22    /// Invalid file id or file header.
23    #[error("invalid file id or file header")]
24    FileInfo,
25    /// No allocated bytes for file id being read.
26    #[error("no allocated bytes for file id being read")]
27    FileInfoAllocated,
28    /// Cannot allocate 0 blocks.
29    #[error("cannot allocate 0 blocks")]
30    AllocateZero,
31    /// Invalid data allocation offsets.
32    #[error("invalid data allocation offsets")]
33    AllocateOffset,
34    /// Insufficient resources.
35    #[error("insufficient resources")]
36    InsufficientResources,
37    /// Invalid file id.
38    #[error("invalid file id")]
39    FileId,
40    /// Invalid data buffer length.
41    #[error("invalid data buffer length")]
42    WriteFileLength,
43    /// Trying to allocate too many blocks.
44    #[error("trying to allocate too many blocks")]
45    WriteFileBlocks,
46    /// Fatal initialization failures
47    #[error("Fatal initialization error: {0}")]
48    Initialization(String),
49    /// Invalid VMGS file format.
50    #[error("VMGS_INVALID_FORMAT: {0}")]
51    InvalidFormat(String),
52    /// Corrupt VMGS file format.
53    #[error("VMGS_CORRUPT_FORMAT: {0}")]
54    CorruptFormat(String),
55    /// Empty VMGS file.
56    #[error("empty file")]
57    EmptyFile,
58    /// Cannot overwrite encrypted file with plaintext data.
59    #[error("cannot overwrite encrypted file with plaintext data")]
60    OverwriteEncrypted,
61    /// Cannot read encrypted file - VMGS is locked.
62    #[error("cannot read encrypted file - VMGS is locked")]
63    ReadEncrypted,
64
65    /// OpenSSL errors.
66    #[cfg(feature = "encryption_ossl")]
67    #[error("OpenSSL error {1}: {0}")]
68    OpenSSL(#[source] openssl::error::ErrorStack, String),
69
70    /// Other errors - TODO: REMOVE THIS
71    #[error(transparent)]
72    Other(#[from] anyhow::Error),
73}