mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: arch/x86_64: 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
28e0a95450
commit
06f3049d24
@@ -133,35 +133,35 @@ pub struct CpuidConfig {
|
||||
pub enum Error {
|
||||
/// Error writing MP table to memory.
|
||||
#[error("Error writing MP table to memory: {0}")]
|
||||
MpTableSetup(mptable::Error),
|
||||
MpTableSetup(#[source] mptable::Error),
|
||||
|
||||
/// Error configuring the general purpose registers
|
||||
#[error("Error configuring the general purpose registers: {0}")]
|
||||
RegsConfiguration(regs::Error),
|
||||
RegsConfiguration(#[source] regs::Error),
|
||||
|
||||
/// Error configuring the special registers
|
||||
#[error("Error configuring the special registers: {0}")]
|
||||
SregsConfiguration(regs::Error),
|
||||
SregsConfiguration(#[source] regs::Error),
|
||||
|
||||
/// Error configuring the floating point related registers
|
||||
#[error("Error configuring the floating point related registers: {0}")]
|
||||
FpuConfiguration(regs::Error),
|
||||
FpuConfiguration(#[source] regs::Error),
|
||||
|
||||
/// Error configuring the MSR registers
|
||||
#[error("Error configuring the MSR registers: {0}")]
|
||||
MsrsConfiguration(regs::Error),
|
||||
MsrsConfiguration(#[source] regs::Error),
|
||||
|
||||
/// Failed to set supported CPUs.
|
||||
#[error("Failed to set supported CPUs: {0}")]
|
||||
SetSupportedCpusFailed(anyhow::Error),
|
||||
SetSupportedCpusFailed(#[source] anyhow::Error),
|
||||
|
||||
/// Cannot set the local interruption due to bad configuration.
|
||||
#[error("Cannot set the local interruption due to bad configuration: {0}")]
|
||||
LocalIntConfiguration(anyhow::Error),
|
||||
LocalIntConfiguration(#[source] anyhow::Error),
|
||||
|
||||
/// Error setting up SMBIOS table
|
||||
#[error("Error setting up SMBIOS table: {0}")]
|
||||
SmbiosSetup(smbios::Error),
|
||||
SmbiosSetup(#[source] smbios::Error),
|
||||
|
||||
/// Could not find any SGX EPC section
|
||||
#[error("Could not find any SGX EPC section")]
|
||||
@@ -177,15 +177,15 @@ pub enum Error {
|
||||
|
||||
/// Error getting supported CPUID through the hypervisor (kvm/mshv) API
|
||||
#[error("Error getting supported CPUID through the hypervisor API: {0}")]
|
||||
CpuidGetSupported(HypervisorError),
|
||||
CpuidGetSupported(#[source] HypervisorError),
|
||||
|
||||
/// Error populating CPUID with KVM HyperV emulation details
|
||||
#[error("Error populating CPUID with KVM HyperV emulation details: {0}")]
|
||||
CpuidKvmHyperV(vmm_sys_util::fam::Error),
|
||||
CpuidKvmHyperV(#[source] vmm_sys_util::fam::Error),
|
||||
|
||||
/// Error populating CPUID with CPU identification
|
||||
#[error("Error populating CPUID with CPU identification: {0}")]
|
||||
CpuidIdentification(vmm_sys_util::fam::Error),
|
||||
CpuidIdentification(#[source] vmm_sys_util::fam::Error),
|
||||
|
||||
/// Error checking CPUID compatibility
|
||||
#[error("Error checking CPUID compatibility")]
|
||||
@@ -193,11 +193,11 @@ pub enum Error {
|
||||
|
||||
// Error writing EBDA address
|
||||
#[error("Error writing EBDA address: {0}")]
|
||||
EbdaSetup(vm_memory::GuestMemoryError),
|
||||
EbdaSetup(#[source] vm_memory::GuestMemoryError),
|
||||
|
||||
// Error getting CPU TSC frequency
|
||||
#[error("Error getting CPU TSC frequency: {0}")]
|
||||
GetTscFrequency(HypervisorCpuError),
|
||||
GetTscFrequency(#[source] HypervisorCpuError),
|
||||
|
||||
/// Error retrieving TDX capabilities through the hypervisor (kvm/mshv) API
|
||||
#[cfg(feature = "tdx")]
|
||||
|
||||
@@ -66,25 +66,25 @@ pub enum Error {
|
||||
TooManyCpus,
|
||||
/// Failure to write the MP floating pointer.
|
||||
#[error("Failure to write the MP floating pointer: {0}")]
|
||||
WriteMpfIntel(GuestMemoryError),
|
||||
WriteMpfIntel(#[source] GuestMemoryError),
|
||||
/// Failure to write MP CPU entry.
|
||||
#[error("Failure to write MP CPU entry: {0}")]
|
||||
WriteMpcCpu(GuestMemoryError),
|
||||
WriteMpcCpu(#[source] GuestMemoryError),
|
||||
/// Failure to write MP ioapic entry.
|
||||
#[error("Failure to write MP ioapic entry: {0}")]
|
||||
WriteMpcIoapic(GuestMemoryError),
|
||||
WriteMpcIoapic(#[source] GuestMemoryError),
|
||||
/// Failure to write MP bus entry.
|
||||
#[error("Failure to write MP bus entry: {0}")]
|
||||
WriteMpcBus(GuestMemoryError),
|
||||
WriteMpcBus(#[source] GuestMemoryError),
|
||||
/// Failure to write MP interrupt source entry.
|
||||
#[error("Failure to write MP interrupt source entry: {0}")]
|
||||
WriteMpcIntsrc(GuestMemoryError),
|
||||
WriteMpcIntsrc(#[source] GuestMemoryError),
|
||||
/// Failure to write MP local interrupt source entry.
|
||||
#[error("Failure to write MP local interrupt source entry: {0}")]
|
||||
WriteMpcLintsrc(GuestMemoryError),
|
||||
WriteMpcLintsrc(#[source] GuestMemoryError),
|
||||
/// Failure to write MP table header.
|
||||
#[error("Failure to write MP table header: {0}")]
|
||||
WriteMpcTable(GuestMemoryError),
|
||||
WriteMpcTable(#[source] GuestMemoryError),
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
@@ -24,40 +24,40 @@ use crate::{EntryPoint, GuestMemoryMmap};
|
||||
pub enum Error {
|
||||
/// Failed to get SREGs for this CPU.
|
||||
#[error("Failed to get SREGs for this CPU: {0}")]
|
||||
GetStatusRegisters(hypervisor::HypervisorCpuError),
|
||||
GetStatusRegisters(#[source] hypervisor::HypervisorCpuError),
|
||||
/// Failed to set base registers for this CPU.
|
||||
#[error("Failed to set base registers for this CPU: {0}")]
|
||||
SetBaseRegisters(hypervisor::HypervisorCpuError),
|
||||
SetBaseRegisters(#[source] hypervisor::HypervisorCpuError),
|
||||
/// Failed to configure the FPU.
|
||||
#[error("Failed to configure the FPU: {0}")]
|
||||
SetFpuRegisters(hypervisor::HypervisorCpuError),
|
||||
SetFpuRegisters(#[source] hypervisor::HypervisorCpuError),
|
||||
/// Setting up MSRs failed.
|
||||
#[error("Setting up MSRs failed: {0}")]
|
||||
SetModelSpecificRegisters(hypervisor::HypervisorCpuError),
|
||||
SetModelSpecificRegisters(#[source] hypervisor::HypervisorCpuError),
|
||||
/// Failed to set SREGs for this CPU.
|
||||
#[error("Failed to set SREGs for this CPU: {0}")]
|
||||
SetStatusRegisters(hypervisor::HypervisorCpuError),
|
||||
SetStatusRegisters(#[source] hypervisor::HypervisorCpuError),
|
||||
/// Checking the GDT address failed.
|
||||
#[error("Checking the GDT address failed")]
|
||||
CheckGdtAddr,
|
||||
/// Writing the GDT to RAM failed.
|
||||
#[error("Writing the GDT to RAM failed: {0}")]
|
||||
WriteGdt(GuestMemoryError),
|
||||
WriteGdt(#[source] GuestMemoryError),
|
||||
/// Writing the IDT to RAM failed.
|
||||
#[error("Writing the IDT to RAM failed: {0}")]
|
||||
WriteIdt(GuestMemoryError),
|
||||
WriteIdt(#[source] GuestMemoryError),
|
||||
/// Writing PDPTE to RAM failed.
|
||||
#[error("Writing PDPTE to RAM failed: {0}")]
|
||||
WritePdpteAddress(GuestMemoryError),
|
||||
WritePdpteAddress(#[source] GuestMemoryError),
|
||||
/// Writing PDE to RAM failed.
|
||||
#[error("Writing PDE to RAM failed: {0}")]
|
||||
WritePdeAddress(GuestMemoryError),
|
||||
WritePdeAddress(#[source] GuestMemoryError),
|
||||
/// Writing PML4 to RAM failed.
|
||||
#[error("Writing PML4 to RAM failed: {0}")]
|
||||
WritePml4Address(GuestMemoryError),
|
||||
WritePml4Address(#[source] GuestMemoryError),
|
||||
/// Writing PML5 to RAM failed.
|
||||
#[error("Writing PML5 to RAM failed: {0}")]
|
||||
WritePml5Address(GuestMemoryError),
|
||||
WritePml5Address(#[source] GuestMemoryError),
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
@@ -34,7 +34,7 @@ pub enum Error {
|
||||
WriteData,
|
||||
/// Failure to parse uuid, uuid format may be error
|
||||
#[error("Failure to parse uuid: {0}")]
|
||||
ParseUuid(uuid::Error),
|
||||
ParseUuid(#[source] uuid::Error),
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
Reference in New Issue
Block a user