Skip to content

Commit ae17df2

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

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

crates/file_store/src/lib.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@ 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+
writeln!(f, "invalid magic bytes")?;
40+
write!(f, " expected: 0x")?;
41+
fmt_hex_bytes(f, expected)?;
42+
writeln!(f)?;
43+
write!(f, " got: 0x")?;
44+
fmt_hex_bytes(f, got)?;
45+
writeln!(f)?;
46+
Ok(())
47+
}
3548
}
3649
}
3750
}

0 commit comments

Comments
 (0)