mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: virtio-devices: 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
a615c809eb
commit
28e0a95450
@@ -65,27 +65,27 @@ const VIRTIO_BALLOON_F_REPORTING: u64 = 5;
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("Guest gave us bad memory addresses.: {0}")]
|
||||
GuestMemory(GuestMemoryError),
|
||||
GuestMemory(#[source] GuestMemoryError),
|
||||
#[error("Guest gave us a write only descriptor that protocol says to read from")]
|
||||
UnexpectedWriteOnlyDescriptor,
|
||||
#[error("Guest sent us invalid request")]
|
||||
InvalidRequest,
|
||||
#[error("Fallocate fail.: {0}")]
|
||||
FallocateFail(std::io::Error),
|
||||
FallocateFail(#[source] std::io::Error),
|
||||
#[error("Madvise fail.: {0}")]
|
||||
MadviseFail(std::io::Error),
|
||||
MadviseFail(#[source] std::io::Error),
|
||||
#[error("Failed to EventFd write.: {0}")]
|
||||
EventFdWriteFail(std::io::Error),
|
||||
EventFdWriteFail(#[source] std::io::Error),
|
||||
#[error("Invalid queue index: {0}")]
|
||||
InvalidQueueIndex(usize),
|
||||
#[error("Fail tp signal: {0}")]
|
||||
FailedSignal(io::Error),
|
||||
FailedSignal(#[source] io::Error),
|
||||
#[error("Descriptor chain is too short")]
|
||||
DescriptorChainTooShort,
|
||||
#[error("Failed adding used index: {0}")]
|
||||
QueueAddUsed(virtio_queue::Error),
|
||||
QueueAddUsed(#[source] virtio_queue::Error),
|
||||
#[error("Failed creating an iterator over the queue: {0}")]
|
||||
QueueIterator(virtio_queue::Error),
|
||||
QueueIterator(#[source] virtio_queue::Error),
|
||||
}
|
||||
|
||||
// Got from include/uapi/linux/virtio_balloon.h
|
||||
|
||||
Reference in New Issue
Block a user