diff --git a/internal/log/log.go b/internal/log/log.go index 361ab53..1a5e8ee 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -1,7 +1,6 @@ package log import ( - "fmt" "io" "io/ioutil" "os" @@ -118,7 +117,7 @@ func (l *Log) Read(off uint64) (*api.Record, error) { // The condition after the of shouldn't matter because we check for this in the for. // The code comes from the book. if s == nil || s.nextOffset <= off { - return nil, fmt.Errorf("offset out of range: %d", off) + return nil, api.ErrOffsetOutOfRange{Offset: off} } return s.Read(off) } diff --git a/internal/log/log_test.go b/internal/log/log_test.go index f2d089f..b8debf0 100644 --- a/internal/log/log_test.go +++ b/internal/log/log_test.go @@ -53,7 +53,8 @@ func testAppendRead(t *testing.T, log *Log) { func testOutOfRangeErr(t *testing.T, log *Log) { read, err := log.Read(1) require.Nil(t, read) - require.Error(t, err) + apiErr := err.(api.ErrOffsetOutOfRange) + require.Equal(t, uint64(1), apiErr.Offset) } func testInitExisting(t *testing.T, o *Log) {