mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: arch/riscv64: 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
d1a406143d
commit
a212343908
+11
-11
@@ -102,7 +102,7 @@ const VIRTIO_MEM_F_ACPI_PXM: u8 = 0;
|
||||
#[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 gave us a read only descriptor that protocol says to write to")]
|
||||
@@ -114,23 +114,23 @@ pub enum Error {
|
||||
#[error("Guest sent us invalid request")]
|
||||
InvalidRequest,
|
||||
#[error("Failed to EventFd write: {0}")]
|
||||
EventFdWriteFail(std::io::Error),
|
||||
EventFdWriteFail(#[source] std::io::Error),
|
||||
#[error("Failed to EventFd try_clone: {0}")]
|
||||
EventFdTryCloneFail(std::io::Error),
|
||||
EventFdTryCloneFail(#[source] std::io::Error),
|
||||
#[error("Failed to MpscRecv: {0}")]
|
||||
MpscRecvFail(mpsc::RecvError),
|
||||
MpscRecvFail(#[source] mpsc::RecvError),
|
||||
#[error("Resize invalid argument: {0}")]
|
||||
ResizeError(anyhow::Error),
|
||||
ResizeError(#[source] anyhow::Error),
|
||||
#[error("Fail to resize trigger: {0}")]
|
||||
ResizeTriggerFail(DeviceError),
|
||||
ResizeTriggerFail(#[source] DeviceError),
|
||||
#[error("Invalid configuration: {0}")]
|
||||
ValidateError(anyhow::Error),
|
||||
ValidateError(#[source] anyhow::Error),
|
||||
#[error("Failed discarding memory range: {0}")]
|
||||
DiscardMemoryRange(std::io::Error),
|
||||
DiscardMemoryRange(#[source] std::io::Error),
|
||||
#[error("Failed DMA mapping: {0}")]
|
||||
DmaMap(std::io::Error),
|
||||
DmaMap(#[source] std::io::Error),
|
||||
#[error("Failed DMA unmapping: {0}")]
|
||||
DmaUnmap(std::io::Error),
|
||||
DmaUnmap(#[source] std::io::Error),
|
||||
#[error("Invalid DMA mapping handler")]
|
||||
InvalidDmaMappingHandler,
|
||||
#[error("Not activated by the guest")]
|
||||
@@ -138,7 +138,7 @@ pub enum Error {
|
||||
#[error("Unknown request type: {0}")]
|
||||
UnknownRequestType(u16),
|
||||
#[error("Failed adding used index: {0}")]
|
||||
QueueAddUsed(virtio_queue::Error),
|
||||
QueueAddUsed(#[source] virtio_queue::Error),
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
||||
Reference in New Issue
Block a user