From dd9bce31e80dd94b0f9bb43cb78cddb563399d11 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 21 May 2025 13:02:29 +0200 Subject: [PATCH] misc: block: streamline #[source] and Error impl This streamlines the Error implementation in the Cloud Hypervisor code base to match the remaining parts so that everything follows the agreed conventions. These are leftovers missed in the previous commits. Signed-off-by: Philipp Schuster On-behalf-of: SAP philipp.schuster@sap.com --- block/src/fcntl.rs | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/block/src/fcntl.rs b/block/src/fcntl.rs index 100b8e1f7..de0289890 100644 --- a/block/src/fcntl.rs +++ b/block/src/fcntl.rs @@ -13,35 +13,25 @@ //! //! [0]: . -use std::error::Error; -use std::fmt::{Debug, Display, Formatter}; +use std::fmt::Debug; use std::io; use std::os::fd::{AsRawFd, RawFd}; +use thiserror::Error; + /// Errors that can happen when working with file locks. -#[derive(Debug)] +#[derive(Error, Debug)] pub enum LockError { /// The file is already locked. /// /// A call to [`get_lock_state`] can help to identify the reason. + #[error("The file is already locked")] AlreadyLocked, /// IO error. - Io(io::Error), + #[error("The lock state could not be checked or set: {0}")] + Io(#[source] io::Error), } -impl Display for LockError { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - LockError::AlreadyLocked => f.write_str("The file is already locked"), - LockError::Io(e) => { - write!(f, "{e}") - } - } - } -} - -impl Error for LockError {} - /// Commands for use with [`fcntl`]. #[allow(non_camel_case_types)] enum FcntlArg<'a> {