misc: net_util: 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:50:35 +02:00
committed by Rob Bradford
parent 8696bc6604
commit fd5cfb75f3
4 changed files with 25 additions and 25 deletions

View File

@@ -13,27 +13,27 @@ use super::{vnet_hdr_len, MacAddr, Tap, TapError};
#[derive(Error, Debug)]
pub enum Error {
#[error("Failed to convert an hexadecimal string into an integer: {0}")]
ConvertHexStringToInt(std::num::ParseIntError),
ConvertHexStringToInt(#[source] std::num::ParseIntError),
#[error("Error related to the multiqueue support (no support TAP side)")]
MultiQueueNoTapSupport,
#[error("Error related to the multiqueue support (no support device side)")]
MultiQueueNoDeviceSupport,
#[error("Failed to read the TAP flags from sysfs: {0}")]
ReadSysfsTunFlags(io::Error),
ReadSysfsTunFlags(#[source] io::Error),
#[error("Open tap device failed: {0}")]
TapOpen(TapError),
TapOpen(#[source] TapError),
#[error("Setting tap IP and/or netmask failed: {0}")]
TapSetIpNetmask(TapError),
TapSetIpNetmask(#[source] TapError),
#[error("Setting MAC address failed: {0}")]
TapSetMac(TapError),
TapSetMac(#[source] TapError),
#[error("Getting MAC address failed: {0}")]
TapGetMac(TapError),
TapGetMac(#[source] TapError),
#[error("Setting vnet header size failed: {0}")]
TapSetVnetHdrSize(TapError),
TapSetVnetHdrSize(#[source] TapError),
#[error("Setting MTU failed: {0}")]
TapSetMtu(TapError),
TapSetMtu(#[source] TapError),
#[error("Enabling tap interface failed: {0}")]
TapEnable(TapError),
TapEnable(#[source] TapError),
}
type Result<T> = std::result::Result<T, Error>;