Skip to content

Commit

Permalink
ParseHeader: print hexdump on error
Browse files Browse the repository at this point in the history
Should help debugging #363
  • Loading branch information
rfjakob committed Feb 17, 2019
1 parent 19cb6d0 commit 179471b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions internal/contentenc/file_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package contentenc
import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"log"

Expand Down Expand Up @@ -52,11 +53,13 @@ func ParseHeader(buf []byte) (*FileHeader, error) {
var h FileHeader
h.Version = binary.BigEndian.Uint16(buf[0:headerVersionLen])
if h.Version != CurrentVersion {
return nil, fmt.Errorf("ParseHeader: invalid version, want=%d have=%d", CurrentVersion, h.Version)
return nil, fmt.Errorf("ParseHeader: invalid version, want=%d have=%d. Hexdump: %s",
CurrentVersion, h.Version, hex.EncodeToString(buf))
}
h.ID = buf[headerVersionLen:]
if bytes.Equal(h.ID, allZeroFileID) {
return nil, fmt.Errorf("ParseHeader: file id is all-zero")
return nil, fmt.Errorf("ParseHeader: file id is all-zero. Hexdump: %s",
hex.EncodeToString(buf))
}
return &h, nil
}
Expand Down
8 changes: 4 additions & 4 deletions tests/matrix/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ func testWriteN(t *testing.T, fn string, n int) string {
}

d := make([]byte, n)
written, err := file.Write(d)
if err != nil || written != len(d) {
t.Errorf("err=\"%s\", written=%d", err, written)
_, err := file.Write(d)
if err != nil {
t.Fatal(err)
}
err = file.Close()
if err != nil {
t.Error(err)
t.Fatal(err)
}

test_helpers.VerifySize(t, test_helpers.DefaultPlainDir+"/"+fn, n)
Expand Down

0 comments on commit 179471b

Please sign in to comment.