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
+14 -14
View File
@@ -88,19 +88,19 @@ pub enum ActivateError {
#[error("Failed to activate virtio device")]
BadActivate,
#[error("Failed to clone exit event fd: {0}")]
CloneExitEventFd(std::io::Error),
CloneExitEventFd(#[source] std::io::Error),
#[error("Failed to spawn thread: {0}")]
ThreadSpawn(std::io::Error),
ThreadSpawn(#[source] std::io::Error),
#[error("Failed to setup vhost-user-fs daemon: {0}")]
VhostUserFsSetup(vhost_user::Error),
VhostUserFsSetup(#[source] vhost_user::Error),
#[error("Failed to setup vhost-user daemon: {0}")]
VhostUserSetup(vhost_user::Error),
VhostUserSetup(#[source] vhost_user::Error),
#[error("Failed to create seccomp filter: {0}")]
CreateSeccompFilter(seccompiler::Error),
CreateSeccompFilter(#[source] seccompiler::Error),
#[error("Failed to create rate limiter: {0}")]
CreateRateLimiter(std::io::Error),
CreateRateLimiter(#[source] std::io::Error),
#[error("Failed to activate the vDPA device: {0}")]
ActivateVdpa(vdpa::Error),
ActivateVdpa(#[source] vdpa::Error),
}
pub type ActivateResult = std::result::Result<(), ActivateError>;
@@ -110,21 +110,21 @@ pub type DeviceEventT = u16;
#[derive(Error, Debug)]
pub enum Error {
#[error("Failed to single used queue: {0}")]
FailedSignalingUsedQueue(io::Error),
FailedSignalingUsedQueue(#[source] io::Error),
#[error("I/O Error: {0}")]
IoError(io::Error),
IoError(#[source] io::Error),
#[error("Failed to update memory vhost-user: {0}")]
VhostUserUpdateMemory(vhost_user::Error),
VhostUserUpdateMemory(#[source] vhost_user::Error),
#[error("Failed to add memory region vhost-user: {0}")]
VhostUserAddMemoryRegion(vhost_user::Error),
VhostUserAddMemoryRegion(#[source] vhost_user::Error),
#[error("Failed to set shared memory region")]
SetShmRegionsNotSupported,
#[error("Failed to process net queue: {0}")]
NetQueuePair(::net_util::NetQueuePairError),
NetQueuePair(#[source] ::net_util::NetQueuePairError),
#[error("Failed to : {0}")]
QueueAddUsed(virtio_queue::Error),
QueueAddUsed(#[source] virtio_queue::Error),
#[error("Failed to : {0}")]
QueueIterator(virtio_queue::Error),
QueueIterator(#[source] virtio_queue::Error),
}
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]