mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: vmm: 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
5db92f79bf
commit
fff62d9302
+29
-14
@@ -29,22 +29,32 @@ use gdbstub_arch::aarch64::AArch64 as GdbArch;
|
||||
use gdbstub_arch::x86::reg::X86_64CoreRegs as CoreRegs;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use gdbstub_arch::x86::X86_64_SSE as GdbArch;
|
||||
use thiserror::Error;
|
||||
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestMemoryError};
|
||||
|
||||
use crate::GuestMemoryMmap;
|
||||
|
||||
type ArchUsize = u64;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum DebuggableError {
|
||||
SetDebug(hypervisor::HypervisorCpuError),
|
||||
Pause(vm_migration::MigratableError),
|
||||
Resume(vm_migration::MigratableError),
|
||||
ReadRegs(crate::cpu::Error),
|
||||
WriteRegs(crate::cpu::Error),
|
||||
ReadMem(GuestMemoryError),
|
||||
WriteMem(GuestMemoryError),
|
||||
TranslateGva(crate::cpu::Error),
|
||||
#[error("Setting debug failed: {0}")]
|
||||
SetDebug(#[source] hypervisor::HypervisorCpuError),
|
||||
#[error("Pausing failed: {0}")]
|
||||
Pause(#[source] vm_migration::MigratableError),
|
||||
#[error("Resuming failed: {0}")]
|
||||
Resume(#[source] vm_migration::MigratableError),
|
||||
#[error("Reading registers failed: {0}")]
|
||||
ReadRegs(#[source] crate::cpu::Error),
|
||||
#[error("Writing registers failed: {0}")]
|
||||
WriteRegs(#[source] crate::cpu::Error),
|
||||
#[error("Reading memory failed: {0}")]
|
||||
ReadMem(#[source] GuestMemoryError),
|
||||
#[error("Writing memory failed: {0}")]
|
||||
WriteMem(#[source] GuestMemoryError),
|
||||
#[error("Translating GVA failed: {0}")]
|
||||
TranslateGva(#[source] crate::cpu::Error),
|
||||
#[error("The lock is poisened")]
|
||||
PoisonedState,
|
||||
}
|
||||
|
||||
@@ -80,13 +90,18 @@ pub trait Debuggable: vm_migration::Pausable {
|
||||
fn active_vcpus(&self) -> usize;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
Vm(crate::vm::Error),
|
||||
#[error("VM failed: {0}")]
|
||||
Vm(#[source] crate::vm::Error),
|
||||
#[error("GDB request failed")]
|
||||
GdbRequest,
|
||||
GdbResponseNotify(std::io::Error),
|
||||
GdbResponse(mpsc::RecvError),
|
||||
GdbResponseTimeout(mpsc::RecvTimeoutError),
|
||||
#[error("GDB couldn't be notified: {0}")]
|
||||
GdbResponseNotify(#[source] std::io::Error),
|
||||
#[error("GDB response failed: {0}")]
|
||||
GdbResponse(#[source] mpsc::RecvError),
|
||||
#[error("GDB response timeout: {0}")]
|
||||
GdbResponseTimeout(#[source] mpsc::RecvTimeoutError),
|
||||
}
|
||||
type GdbResult<T> = std::result::Result<T, Error>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user