Skip to content

Commit 961118b

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

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

crates/file_store/src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ pub enum StoreError {
2626
impl core::fmt::Display for StoreError {
2727
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2828
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-
),
29+
Self::Io(e) => write!(f, "io error trying to read file: {}", e),
30+
Self::InvalidMagicBytes { got, expected } => {
31+
write!(f, "file has invalid magic bytes: expected=0x")?;
32+
for b in expected {
33+
write!(f, "{:02x}", b)?;
34+
}
35+
write!(f, " got=0x")?;
36+
for b in got {
37+
write!(f, "{:02x}", b)?;
38+
}
39+
Ok(())
40+
}
3441
Self::Bincode(e) => write!(f, "bincode error while reading entry {e}"),
3542
}
3643
}

0 commit comments

Comments
 (0)