misc: replace manual From<T> for *Error with #[from]

This is a small simplification we can use since we use `thiserror`
anyway. Note that `#[from]` implies `#[source]` [0].

[0]: https://docs.rs/thiserror/2.0.12/thiserror/index.html

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-06-12 16:44:11 +02:00
committed by Rob Bradford
parent d594107c0d
commit 9bd9c0cb71
7 changed files with 6 additions and 42 deletions

View File

@@ -56,12 +56,6 @@ pub enum Error {
VcpuInitPmu,
}
impl From<Error> for super::Error {
fn from(e: Error) -> super::Error {
super::Error::PlatformSpecific(e)
}
}
#[derive(Debug, Copy, Clone)]
/// Specifies the entry point address where the guest must start
/// executing code.

View File

@@ -29,13 +29,13 @@ type GuestRegionMmap = vm_memory::GuestRegionMmap<vm_memory::bitmap::AtomicBitma
pub enum Error {
#[cfg(target_arch = "x86_64")]
#[error("Platform specific error (x86_64): {0}")]
PlatformSpecific(#[source] x86_64::Error),
PlatformSpecific(#[from] x86_64::Error),
#[cfg(target_arch = "aarch64")]
#[error("Platform specific error (aarch64): {0:?}")]
PlatformSpecific(#[source] aarch64::Error),
PlatformSpecific(#[from] aarch64::Error),
#[cfg(target_arch = "riscv64")]
#[error("Platform specific error (riscv64): {0:?}")]
PlatformSpecific(#[source] riscv64::Error),
PlatformSpecific(#[from] riscv64::Error),
#[error("The memory map table extends past the end of guest memory")]
MemmapTablePastRamEnd,
#[error("Error writing memory map table to guest memory")]

View File

@@ -46,12 +46,6 @@ pub enum Error {
RegsConfiguration(#[source] hypervisor::HypervisorCpuError),
}
impl From<Error> for super::Error {
fn from(e: Error) -> super::Error {
super::Error::PlatformSpecific(e)
}
}
#[derive(Debug, Copy, Clone)]
/// Specifies the entry point address where the guest must start
/// executing code.

View File

@@ -209,12 +209,6 @@ pub enum Error {
E820Configuration,
}
impl From<Error> for super::Error {
fn from(e: Error) -> super::Error {
super::Error::PlatformSpecific(e)
}
}
pub fn get_x2apic_id(cpu_id: u32, topology: Option<(u8, u8, u8)>) -> u32 {
if let Some(t) = topology {
let thread_mask_width = u8::BITS - (t.0 - 1).leading_zeros();

View File

@@ -25,17 +25,11 @@ enum Error {
#[error("boot time could not be parsed")]
BootTimeParse,
#[error("infrastructure failure: {0}")]
Infra(#[source] InfraError),
Infra(#[from] InfraError),
#[error("restore time could not be parsed")]
RestoreTimeParse,
}
impl From<InfraError> for Error {
fn from(e: InfraError) -> Self {
Self::Infra(e)
}
}
const BLK_IO_TEST_IMG: &str = "/var/tmp/ch-blk-io-test.img";
pub fn init_tests() {

View File

@@ -40,7 +40,7 @@ pub enum Error {
#[error("Failed to parse: {0}")]
Parsing(#[source] std::num::ParseIntError),
#[error("ssh command failed: {0}")]
SshCommand(#[source] SshCommandError),
SshCommand(#[from] SshCommandError),
#[error("waiting for boot failed: {0}")]
WaitForBoot(#[source] WaitForBootError),
#[error("reading log file failed: {0}")]
@@ -57,12 +57,6 @@ pub enum Error {
WaitTimeout(#[source] WaitTimeoutError),
}
impl From<SshCommandError> for Error {
fn from(e: SshCommandError) -> Self {
Self::SshCommand(e)
}
}
pub struct GuestNetworkConfig {
pub guest_ip: String,
pub l2_guest_ip1: String,

View File

@@ -44,7 +44,7 @@ pub type HttpApiHandle = (thread::JoinHandle<Result<()>>, EventFd);
pub enum HttpError {
/// API request receive error
#[error("Failed to deserialize JSON: {0}")]
SerdeJsonDeserialize(#[source] SerdeError),
SerdeJsonDeserialize(#[from] SerdeError),
/// Attempt to access unsupported HTTP method
#[error("Bad Request")]
@@ -67,12 +67,6 @@ pub enum HttpError {
ApiError(#[source] ApiError),
}
impl From<serde_json::Error> for HttpError {
fn from(e: serde_json::Error) -> Self {
HttpError::SerdeJsonDeserialize(e)
}
}
const HTTP_ROOT: &str = "/api/v1";
pub fn error_response(error: HttpError, status: StatusCode) -> Response {