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
+3
-2
@@ -40,6 +40,7 @@ use std::sync::mpsc::{channel, RecvError, SendError, Sender};
|
||||
|
||||
use micro_http::Body;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
use vm_migration::MigratableError;
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
@@ -56,10 +57,10 @@ use crate::vm_config::{
|
||||
use crate::Error as VmmError;
|
||||
|
||||
/// API errors are sent back from the VMM API server through the ApiResponse.
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ApiError {
|
||||
/// Cannot write to EventFd.
|
||||
EventFdWrite(io::Error),
|
||||
EventFdWrite(#[source] io::Error),
|
||||
|
||||
/// API request send error
|
||||
RequestSend(SendError<ApiRequest>),
|
||||
|
||||
+26
-26
@@ -41,81 +41,81 @@ pub enum Error {
|
||||
/// Missing restore source_url parameter.
|
||||
ParseRestoreSourceUrlMissing,
|
||||
/// Error parsing CPU options
|
||||
ParseCpus(OptionParserError),
|
||||
ParseCpus(#[source] OptionParserError),
|
||||
/// Invalid CPU features
|
||||
InvalidCpuFeatures(String),
|
||||
/// Error parsing memory options
|
||||
ParseMemory(OptionParserError),
|
||||
ParseMemory(#[source] OptionParserError),
|
||||
/// Error parsing memory zone options
|
||||
ParseMemoryZone(OptionParserError),
|
||||
ParseMemoryZone(#[source] OptionParserError),
|
||||
/// Missing 'id' from memory zone
|
||||
ParseMemoryZoneIdMissing,
|
||||
/// Error parsing rate-limiter group options
|
||||
ParseRateLimiterGroup(OptionParserError),
|
||||
ParseRateLimiterGroup(#[source] OptionParserError),
|
||||
/// Error parsing disk options
|
||||
ParseDisk(OptionParserError),
|
||||
ParseDisk(#[source] OptionParserError),
|
||||
/// Error parsing network options
|
||||
ParseNetwork(OptionParserError),
|
||||
ParseNetwork(#[source] OptionParserError),
|
||||
/// Error parsing RNG options
|
||||
ParseRng(OptionParserError),
|
||||
ParseRng(#[source] OptionParserError),
|
||||
/// Error parsing balloon options
|
||||
ParseBalloon(OptionParserError),
|
||||
ParseBalloon(#[source] OptionParserError),
|
||||
/// Error parsing filesystem parameters
|
||||
ParseFileSystem(OptionParserError),
|
||||
ParseFileSystem(#[source] OptionParserError),
|
||||
/// Error parsing persistent memory parameters
|
||||
ParsePersistentMemory(OptionParserError),
|
||||
ParsePersistentMemory(#[source] OptionParserError),
|
||||
/// Failed parsing console
|
||||
ParseConsole(OptionParserError),
|
||||
ParseConsole(#[source] OptionParserError),
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
/// Failed parsing debug-console
|
||||
ParseDebugConsole(OptionParserError),
|
||||
ParseDebugConsole(#[source] OptionParserError),
|
||||
/// No mode given for console
|
||||
ParseConsoleInvalidModeGiven,
|
||||
/// Failed parsing device parameters
|
||||
ParseDevice(OptionParserError),
|
||||
ParseDevice(#[source] OptionParserError),
|
||||
/// Missing path from device,
|
||||
ParseDevicePathMissing,
|
||||
/// Failed parsing vsock parameters
|
||||
ParseVsock(OptionParserError),
|
||||
ParseVsock(#[source] OptionParserError),
|
||||
/// Failed parsing restore parameters
|
||||
ParseRestore(OptionParserError),
|
||||
ParseRestore(#[source] OptionParserError),
|
||||
/// Failed parsing SGX EPC parameters
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
ParseSgxEpc(OptionParserError),
|
||||
ParseSgxEpc(#[source] OptionParserError),
|
||||
/// Missing 'id' from SGX EPC section
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
ParseSgxEpcIdMissing,
|
||||
/// Failed parsing NUMA parameters
|
||||
ParseNuma(OptionParserError),
|
||||
ParseNuma(#[source] OptionParserError),
|
||||
/// Failed validating configuration
|
||||
Validation(ValidationError),
|
||||
Validation(#[source] ValidationError),
|
||||
#[cfg(feature = "sev_snp")]
|
||||
/// Failed parsing SEV-SNP config
|
||||
ParseSevSnp(OptionParserError),
|
||||
ParseSevSnp(#[source] OptionParserError),
|
||||
#[cfg(feature = "tdx")]
|
||||
/// Failed parsing TDX config
|
||||
ParseTdx(OptionParserError),
|
||||
ParseTdx(#[source] OptionParserError),
|
||||
#[cfg(feature = "tdx")]
|
||||
/// No TDX firmware
|
||||
FirmwarePathMissing,
|
||||
/// Failed parsing userspace device
|
||||
ParseUserDevice(OptionParserError),
|
||||
ParseUserDevice(#[source] OptionParserError),
|
||||
/// Missing socket for userspace device
|
||||
ParseUserDeviceSocketMissing,
|
||||
/// Error parsing pci segment options
|
||||
ParsePciSegment(OptionParserError),
|
||||
ParsePciSegment(#[source] OptionParserError),
|
||||
/// Failed parsing platform parameters
|
||||
ParsePlatform(OptionParserError),
|
||||
ParsePlatform(#[source] OptionParserError),
|
||||
/// Failed parsing vDPA device
|
||||
ParseVdpa(OptionParserError),
|
||||
ParseVdpa(#[source] OptionParserError),
|
||||
/// Missing path for vDPA device
|
||||
ParseVdpaPathMissing,
|
||||
/// Failed parsing TPM device
|
||||
ParseTpm(OptionParserError),
|
||||
ParseTpm(#[source] OptionParserError),
|
||||
/// Missing path for TPM device
|
||||
ParseTpmPathMissing,
|
||||
/// Error parsing Landlock rules
|
||||
ParseLandlockRules(OptionParserError),
|
||||
ParseLandlockRules(#[source] OptionParserError),
|
||||
/// Missing fields in Landlock rules
|
||||
ParseLandlockMissingFields,
|
||||
}
|
||||
|
||||
+1
-1
@@ -204,7 +204,7 @@ pub enum Error {
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[error("Failed to inject NMI")]
|
||||
NmiError(hypervisor::HypervisorCpuError),
|
||||
NmiError(#[source] hypervisor::HypervisorCpuError),
|
||||
}
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
|
||||
+11
-10
@@ -145,15 +145,15 @@ pub enum Error {
|
||||
|
||||
/// Cannot handle the VM STDIN stream
|
||||
#[error("Error handling VM stdin: {0:?}")]
|
||||
Stdin(VmError),
|
||||
Stdin(#[source] VmError),
|
||||
|
||||
/// Cannot handle the VM pty stream
|
||||
#[error("Error handling VM pty: {0:?}")]
|
||||
Pty(VmError),
|
||||
Pty(#[source] VmError),
|
||||
|
||||
/// Cannot reboot the VM
|
||||
#[error("Error rebooting VM: {0:?}")]
|
||||
VmReboot(VmError),
|
||||
VmReboot(#[source] VmError),
|
||||
|
||||
/// Cannot create VMM thread
|
||||
#[error("Error spawning VMM thread {0:?}")]
|
||||
@@ -161,22 +161,23 @@ pub enum Error {
|
||||
|
||||
/// Cannot shut the VMM down
|
||||
#[error("Error shutting down VMM: {0:?}")]
|
||||
VmmShutdown(VmError),
|
||||
VmmShutdown(#[source] VmError),
|
||||
|
||||
/// Cannot create seccomp filter
|
||||
#[error("Error creating seccomp filter: {0}")]
|
||||
CreateSeccompFilter(seccompiler::Error),
|
||||
CreateSeccompFilter(#[source] seccompiler::Error),
|
||||
|
||||
/// Cannot apply seccomp filter
|
||||
#[error("Error applying seccomp filter: {0}")]
|
||||
ApplySeccompFilter(seccompiler::Error),
|
||||
ApplySeccompFilter(#[source] seccompiler::Error),
|
||||
|
||||
/// Error activating virtio devices
|
||||
#[error("Error activating virtio devices: {0:?}")]
|
||||
ActivateVirtioDevices(VmError),
|
||||
ActivateVirtioDevices(#[source] VmError),
|
||||
|
||||
/// Error creating API server
|
||||
#[error("Error creating API server {0:?}")]
|
||||
// TODO #[source] once the type implements Error
|
||||
CreateApiServer(micro_http::ServerError),
|
||||
|
||||
/// Error binding API server socket
|
||||
@@ -185,7 +186,7 @@ pub enum Error {
|
||||
|
||||
#[cfg(feature = "guest_debug")]
|
||||
#[error("Failed to start the GDB thread: {0}")]
|
||||
GdbThreadSpawn(io::Error),
|
||||
GdbThreadSpawn(#[source] io::Error),
|
||||
|
||||
/// GDB request receive error
|
||||
#[cfg(feature = "guest_debug")]
|
||||
@@ -205,11 +206,11 @@ pub enum Error {
|
||||
|
||||
/// Cannot create Landlock object
|
||||
#[error("Error creating landlock object: {0}")]
|
||||
CreateLandlock(LandlockError),
|
||||
CreateLandlock(#[source] LandlockError),
|
||||
|
||||
/// Cannot apply landlock based sandboxing
|
||||
#[error("Error applying landlock: {0}")]
|
||||
ApplyLandlock(LandlockError),
|
||||
ApplyLandlock(#[source] LandlockError),
|
||||
}
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
|
||||
+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