From: Dmenec Date: Thu, 11 Dec 2025 11:02:28 +0000 (+0100) Subject: fix(file_store)!: remove Debug usage and implement Display for StoreError. X-Git-Url: http://internal-gitweb-vhost/%22https:/parse/scripts/-sqlite/database/struct.CommandStringError.html?a=commitdiff_plain;h=823e4e980af03672cc6342d0e4850febcbd14c9d;p=bdk fix(file_store)!: remove Debug usage and implement Display for StoreError. Format magic bytes as 0x-prefixed hex. --- diff --git a/crates/file_store/src/lib.rs b/crates/file_store/src/lib.rs index d7dd35bf..5a7d5030 100644 --- a/crates/file_store/src/lib.rs +++ b/crates/file_store/src/lib.rs @@ -25,13 +25,24 @@ pub enum StoreError { impl core::fmt::Display for StoreError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + fn fmt_hex_bytes(f: &mut core::fmt::Formatter<'_>, bytes: &[u8]) -> core::fmt::Result { + for &b in bytes { + write!(f, "{:02x}", b)?; + } + Ok(()) + } + match self { - Self::Io(e) => write!(f, "io error trying to read file: {e}"), - Self::InvalidMagicBytes { got, expected } => write!( - f, - "file has invalid magic bytes: expected={expected:?} got={got:?}", - ), - Self::Bincode(e) => write!(f, "bincode error while reading entry {e}"), + Self::Io(e) => write!(f, "io error while reading store file: {}", e), + Self::Bincode(e) => write!(f, "bincode error while decoding entry {}", e), + Self::InvalidMagicBytes { got, expected } => { + write!(f, "invalid magic bytes: ")?; + write!(f, "expected 0x")?; + fmt_hex_bytes(f, expected)?; + write!(f, ", got 0x")?; + fmt_hex_bytes(f, got)?; + Ok(()) + } } } }