From c7d0d10da43c5486925870697ee5c5abf0d070d1 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Wed, 19 Sep 2018 11:40:07 +0530 Subject: [PATCH] Make sure WAL Repair can handle wrapped errors Signed-off-by: Goutham Veeramachaneni --- wal/wal.go | 6 ++++-- wal/wal_test.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wal/wal.go b/wal/wal.go index 0e95ba2a..1aea24d8 100644 --- a/wal/wal.go +++ b/wal/wal.go @@ -255,15 +255,17 @@ Loop: // Repair attempts to repair the WAL based on the error. // It discards all data after the corruption. -func (w *WAL) Repair(err error) error { +func (w *WAL) Repair(origErr error) error { // We could probably have a mode that only discards torn records right around // the corruption to preserve as data much as possible. // But that's not generally applicable if the records have any kind of causality. // Maybe as an extra mode in the future if mid-WAL corruptions become // a frequent concern. + err := errors.Cause(origErr) // So that we can pick up errors even if wrapped. + cerr, ok := err.(*CorruptionErr) if !ok { - return errors.New("cannot handle error") + return errors.Wrap(origErr, "cannot handle error") } if cerr.Segment < 0 { return errors.New("corruption error does not specify position") diff --git a/wal/wal_test.go b/wal/wal_test.go index d1b724c7..26ee8663 100644 --- a/wal/wal_test.go +++ b/wal/wal_test.go @@ -23,6 +23,7 @@ import ( "os" "testing" + "github.com/pkg/errors" "github.com/prometheus/tsdb/testutil" ) @@ -286,8 +287,8 @@ func TestWAL_Repair(t *testing.T) { for r.Next() { } testutil.NotOk(t, r.Err()) - testutil.Ok(t, w.Repair(r.Err())) + testutil.Ok(t, w.Repair(errors.Wrap(r.Err(), "err"))) // See https://github.com/prometheus/prometheus/issues/4603 sr, err = NewSegmentsReader(dir) testutil.Ok(t, err)