Change log implementation to return the custom error.
This commit is contained in:
parent
4ec590a7cf
commit
d480067e8a
2 changed files with 3 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue