From d1a406143d4688c14eaaee6555c983e9cd3f6f19 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Mon, 19 May 2025 09:46:08 +0200 Subject: [PATCH] misc: arch/aarch64: 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 On-behalf-of: SAP philipp.schuster@sap.com --- arch/src/aarch64/fdt.rs | 2 +- arch/src/aarch64/mod.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/src/aarch64/fdt.rs b/arch/src/aarch64/fdt.rs index 95831ae67..30c754d6f 100644 --- a/arch/src/aarch64/fdt.rs +++ b/arch/src/aarch64/fdt.rs @@ -82,7 +82,7 @@ pub trait DeviceInfoForFdt { pub enum Error { /// Failure in writing FDT in memory. #[error("Failure in writing FDT in memory: {0}")] - WriteFdtToMemory(GuestMemoryError), + WriteFdtToMemory(#[source] GuestMemoryError), } type Result = result::Result; diff --git a/arch/src/aarch64/mod.rs b/arch/src/aarch64/mod.rs index 78f44e89d..d0a6eb002 100644 --- a/arch/src/aarch64/mod.rs +++ b/arch/src/aarch64/mod.rs @@ -33,7 +33,7 @@ pub enum Error { /// Failed to write FDT to memory. #[error("Failed to write FDT to memory: {0}")] - WriteFdtToMemory(fdt::Error), + WriteFdtToMemory(#[source] fdt::Error), /// Failed to create a GIC. #[error("Failed to create a GIC")] @@ -45,11 +45,11 @@ pub enum Error { /// Error configuring the general purpose registers #[error("Error configuring the general purpose registers: {0}")] - RegsConfiguration(hypervisor::HypervisorCpuError), + RegsConfiguration(#[source] hypervisor::HypervisorCpuError), /// Error configuring the MPIDR register #[error("Error configuring the MPIDR register: {0}")] - VcpuRegMpidr(hypervisor::HypervisorCpuError), + VcpuRegMpidr(#[source] hypervisor::HypervisorCpuError), /// Error initializing PMU for vcpu #[error("Error initializing PMU for vcpu")]