mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: block: streamline #[source] and Error
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
a212343908
commit
01761c2596
@@ -37,23 +37,23 @@ const MAX_NESTING_DEPTH: u32 = 10;
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("Backing file io error: {0}")]
|
||||
BackingFileIo(io::Error),
|
||||
BackingFileIo(#[source] io::Error),
|
||||
#[error("Backing file open error: {0}")]
|
||||
BackingFileOpen(Box<Error>),
|
||||
BackingFileOpen(#[source] Box<Error>),
|
||||
#[error("Backing file name is too long: {0} bytes over")]
|
||||
BackingFileTooLong(usize),
|
||||
#[error("Compressed blocks not supported")]
|
||||
CompressedBlocksNotSupported,
|
||||
#[error("Failed to evict cache: {0}")]
|
||||
EvictingCache(io::Error),
|
||||
EvictingCache(#[source] io::Error),
|
||||
#[error("File larger than max of {MAX_QCOW_FILE_SIZE}: {0}")]
|
||||
FileTooBig(u64),
|
||||
#[error("Failed to get file size: {0}")]
|
||||
GettingFileSize(io::Error),
|
||||
GettingFileSize(#[source] io::Error),
|
||||
#[error("Failed to get refcount: {0}")]
|
||||
GettingRefcount(refcount::Error),
|
||||
GettingRefcount(#[source] refcount::Error),
|
||||
#[error("Failed to parse filename: {0}")]
|
||||
InvalidBackingFileName(str::Utf8Error),
|
||||
InvalidBackingFileName(#[source] str::Utf8Error),
|
||||
#[error("Invalid cluster index")]
|
||||
InvalidClusterIndex,
|
||||
#[error("Invalid cluster size")]
|
||||
@@ -81,29 +81,29 @@ pub enum Error {
|
||||
#[error("Not enough space for refcounts")]
|
||||
NotEnoughSpaceForRefcounts,
|
||||
#[error("Failed to open file {0}")]
|
||||
OpeningFile(io::Error),
|
||||
OpeningFile(#[source] io::Error),
|
||||
#[error("Failed to read data: {0}")]
|
||||
ReadingData(io::Error),
|
||||
ReadingData(#[source] io::Error),
|
||||
#[error("Failed to read header: {0}")]
|
||||
ReadingHeader(io::Error),
|
||||
ReadingHeader(#[source] io::Error),
|
||||
#[error("Failed to read pointers: {0}")]
|
||||
ReadingPointers(io::Error),
|
||||
ReadingPointers(#[source] io::Error),
|
||||
#[error("Failed to read ref count block: {0}")]
|
||||
ReadingRefCountBlock(refcount::Error),
|
||||
ReadingRefCountBlock(#[source] refcount::Error),
|
||||
#[error("Failed to read ref counts: {0}")]
|
||||
ReadingRefCounts(io::Error),
|
||||
ReadingRefCounts(#[source] io::Error),
|
||||
#[error("Failed to rebuild ref counts: {0}")]
|
||||
RebuildingRefCounts(io::Error),
|
||||
RebuildingRefCounts(#[source] io::Error),
|
||||
#[error("Refcount table offset past file end")]
|
||||
RefcountTableOffEnd,
|
||||
#[error("Too many clusters specified for refcount")]
|
||||
RefcountTableTooLarge,
|
||||
#[error("Failed to seek file: {0}")]
|
||||
SeekingFile(io::Error),
|
||||
SeekingFile(#[source] io::Error),
|
||||
#[error("Failed to set file size: {0}")]
|
||||
SettingFileSize(io::Error),
|
||||
SettingFileSize(#[source] io::Error),
|
||||
#[error("Failed to set refcount refcount: {0}")]
|
||||
SettingRefcountRefcount(io::Error),
|
||||
SettingRefcountRefcount(#[source] io::Error),
|
||||
#[error("Size too small for number of clusters")]
|
||||
SizeTooSmallForNumberOfClusters,
|
||||
#[error("L1 entry table too large: {0}")]
|
||||
@@ -115,9 +115,9 @@ pub enum Error {
|
||||
#[error("Unsupported version: {0}")]
|
||||
UnsupportedVersion(u32),
|
||||
#[error("Failed to write data: {0}")]
|
||||
WritingData(io::Error),
|
||||
WritingData(#[source] io::Error),
|
||||
#[error("Failed to write header: {0}")]
|
||||
WritingHeader(io::Error),
|
||||
WritingHeader(#[source] io::Error),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::qcow::vec_cache::{CacheMap, Cacheable, VecCache};
|
||||
pub enum Error {
|
||||
/// `EvictingCache` - Error writing a refblock from the cache to disk.
|
||||
#[error("Failed to write a refblock from the cache to disk: {0}")]
|
||||
EvictingRefCounts(io::Error),
|
||||
EvictingRefCounts(#[source] io::Error),
|
||||
/// `InvalidIndex` - Address requested isn't within the range of the disk.
|
||||
#[error("Address requested is not within the range of the disk")]
|
||||
InvalidIndex,
|
||||
@@ -28,7 +28,7 @@ pub enum Error {
|
||||
NeedNewCluster,
|
||||
/// `ReadingRefCounts` - Error reading the file into the refcount cache.
|
||||
#[error("Failed to read the file into the refcount cache: {0}")]
|
||||
ReadingRefCounts(io::Error),
|
||||
ReadingRefCounts(#[source] io::Error),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
Reference in New Issue
Block a user