]> Untitled Git - bdk/commitdiff
fix(file_store)!: remove Debug usage and implement Display for StoreError.
authorDmenec <Domenec.Madrid@uab.cat>
Thu, 11 Dec 2025 11:02:28 +0000 (12:02 +0100)
committerDmenec <Domenec.Madrid@uab.cat>
Thu, 5 Feb 2026 12:30:50 +0000 (13:30 +0100)
Format magic bytes as 0x-prefixed hex.

crates/file_store/src/lib.rs

index d7dd35bf477a64e7f320d0d970428b1c05ac1e1b..5a7d50304c55146bc9400380d0d6e339e4d2fa88 100644 (file)
@@ -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(())
+            }
         }
     }
 }