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> {