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

View File

@@ -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>),