Skip to content

Commit 823e4e9

Browse files
committed
fix(file_store)!: remove Debug usage and implement Display for StoreError.
Format magic bytes as 0x-prefixed hex.
1 parent 5a85f6e commit 823e4e9

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

crates/file_store/src/lib.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,24 @@ pub enum StoreError {
2525

2626
impl core::fmt::Display for StoreError {
2727
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
28+
fn fmt_hex_bytes(f: &mut core::fmt::Formatter<'_>, bytes: &[u8]) -> core::fmt::Result {
29+
for &b in bytes {
30+
write!(f, "{:02x}", b)?;
31+
}
32+
Ok(())
33+
}
34+
2835
match self {
29-
Self::Io(e) => write!(f, "io error trying to read file: {e}"),
30-
Self::InvalidMagicBytes { got, expected } => write!(
31-
f,
32-
"file has invalid magic bytes: expected={expected:?} got={got:?}",
33-
),
34-
Self::Bincode(e) => write!(f, "bincode error while reading entry {e}"),
36+
Self::Io(e) => write!(f, "io error while reading store file: {}", e),
37+
Self::Bincode(e) => write!(f, "bincode error while decoding entry {}", e),
38+
Self::InvalidMagicBytes { got, expected } => {
39+
write!(f, "invalid magic bytes: ")?;
40+
write!(f, "expected 0x")?;
41+
fmt_hex_bytes(f, expected)?;
42+
write!(f, ", got 0x")?;
43+
fmt_hex_bytes(f, got)?;
44+
Ok(())
45+
}
3546
}
3647
}
3748
}

0 commit comments

Comments
 (0)