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:
Philipp Schuster
2025-05-19 09:49:51 +02:00
committed by Rob Bradford
parent d1a406143d
commit a212343908
17 changed files with 179 additions and 174 deletions
+11 -10
View File
@@ -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>;