diff --git a/component/common/loki/wal/watcher.go b/component/common/loki/wal/watcher.go index 23570a9f5a55..007648c808f1 100644 --- a/component/common/loki/wal/watcher.go +++ b/component/common/loki/wal/watcher.go @@ -1,6 +1,7 @@ package wal import ( + "errors" "fmt" "io" "math" @@ -190,7 +191,7 @@ func (w *Watcher) watch(segmentNum int) error { } // io.EOF error are non-fatal since we are tailing the wal - if errorCause(err) != io.EOF { + if errors.Unwrap(err) != io.EOF { return err } @@ -215,7 +216,7 @@ func (w *Watcher) watch(segmentNum int) error { } // io.EOF error are non-fatal since we are tailing the wal - if errorCause(err) != io.EOF { + if errors.Unwrap(err) != io.EOF { return err } @@ -348,20 +349,3 @@ func readSegmentNumbers(dir string) ([]int, error) { } return refs, nil } - -// errorCause gets the underlying error case, if this implements the causer interface. -// Inlining to avoid using deny-listed dependency. -func errorCause(err error) error { - type causer interface { - Cause() error - } - - for err != nil { - cause, ok := err.(causer) - if !ok { - break - } - err = cause.Cause() - } - return err -} diff --git a/component/common/loki/wal/watcher_test.go b/component/common/loki/wal/watcher_test.go index b9f57dc8fcd5..de5be3a72a30 100644 --- a/component/common/loki/wal/watcher_test.go +++ b/component/common/loki/wal/watcher_test.go @@ -168,10 +168,10 @@ var cases = map[string]watcherTest{ require.Eventually(t, func() bool { return res.writeTo.ReadEntries.Length() == 3 }, time.Second*10, time.Second, "expected watcher to catch up with written entries") - defer res.writeTo.ReadEntries.DoneIterate() for _, readEntry := range res.writeTo.ReadEntries.StartIterate() { require.Contains(t, lines, readEntry.Line, "not expected log line") } + res.writeTo.ReadEntries.DoneIterate() err := res.nextWALSegment() require.NoError(t, err, "expected no error when moving to next wal segment")