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
+10
-10
@@ -142,10 +142,10 @@ pub enum Error {
|
||||
PoisonedState,
|
||||
|
||||
#[error("Error from device manager: {0:?}")]
|
||||
DeviceManager(DeviceManagerError),
|
||||
DeviceManager(#[source] DeviceManagerError),
|
||||
|
||||
#[error("Error initializing VM: {0:?}")]
|
||||
InitializeVm(hypervisor::HypervisorVmError),
|
||||
InitializeVm(#[source] hypervisor::HypervisorVmError),
|
||||
|
||||
#[error("No device with id {0:?} to remove")]
|
||||
NoDeviceToRemove(String),
|
||||
@@ -196,7 +196,7 @@ pub enum Error {
|
||||
Resume(#[source] MigratableError),
|
||||
|
||||
#[error("Memory manager error: {0:?}")]
|
||||
MemoryManager(MemoryManagerError),
|
||||
MemoryManager(#[source] MemoryManagerError),
|
||||
|
||||
#[error("Eventfd write error: {0}")]
|
||||
EventfdError(#[source] std::io::Error),
|
||||
@@ -235,16 +235,16 @@ pub enum Error {
|
||||
ResizeZone,
|
||||
|
||||
#[error("Cannot activate virtio devices: {0:?}")]
|
||||
ActivateVirtioDevices(DeviceManagerError),
|
||||
ActivateVirtioDevices(#[source] DeviceManagerError),
|
||||
|
||||
#[error("Error triggering power button: {0:?}")]
|
||||
PowerButton(DeviceManagerError),
|
||||
PowerButton(#[source] DeviceManagerError),
|
||||
|
||||
#[error("Kernel lacks PVH header")]
|
||||
KernelMissingPvhHeader,
|
||||
|
||||
#[error("Failed to allocate firmware RAM: {0:?}")]
|
||||
AllocateFirmwareMemory(MemoryManagerError),
|
||||
AllocateFirmwareMemory(#[source] MemoryManagerError),
|
||||
|
||||
#[error("Error manipulating firmware file: {0}")]
|
||||
FirmwareFile(#[source] std::io::Error),
|
||||
@@ -304,7 +304,7 @@ pub enum Error {
|
||||
Debug(DebuggableError),
|
||||
|
||||
#[error("Error spawning kernel loading thread")]
|
||||
KernelLoadThreadSpawn(std::io::Error),
|
||||
KernelLoadThreadSpawn(#[source] std::io::Error),
|
||||
|
||||
#[error("Error joining kernel loading thread")]
|
||||
KernelLoadThreadJoin(std::boxed::Box<dyn std::any::Any + std::marker::Send>),
|
||||
@@ -314,7 +314,7 @@ pub enum Error {
|
||||
|
||||
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
|
||||
#[error("Error coredumping VM: {0:?}")]
|
||||
Coredump(GuestDebuggableError),
|
||||
Coredump(#[source] GuestDebuggableError),
|
||||
|
||||
#[cfg(feature = "igvm")]
|
||||
#[error("Cannot open igvm file: {0}")]
|
||||
@@ -331,10 +331,10 @@ pub enum Error {
|
||||
ResumeVm(#[source] hypervisor::HypervisorVmError),
|
||||
|
||||
#[error("Error creating console devices")]
|
||||
CreateConsoleDevices(ConsoleDeviceError),
|
||||
CreateConsoleDevices(#[source] ConsoleDeviceError),
|
||||
|
||||
#[error("Error locking disk images: Another instance likely holds a lock")]
|
||||
LockingError(DeviceManagerError),
|
||||
LockingError(#[source] DeviceManagerError),
|
||||
}
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user