@@ -25,13 +25,24 @@ pub enum StoreError {
2525
2626impl 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