From b10381fbe0512a4c2081f7aa5ec97bd74c9f5c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 2 Dec 2021 16:49:44 +0100 Subject: [PATCH] lazy: Reset error in Reset To prevent sticky errors on server rebuilds. Fixes #7043 Closes #9194 --- lazy/init.go | 1 + lazy/init_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lazy/init.go b/lazy/init.go index e2e70072e..6dff0c98c 100644 --- a/lazy/init.go +++ b/lazy/init.go @@ -136,6 +136,7 @@ func (ini *Init) shouldInitialize() bool { // Reset resets the current and all its dependencies. func (ini *Init) Reset() { mu := ini.init.ResetWithLock() + ini.err = nil defer mu.Unlock() for _, d := range ini.children { d.Reset() diff --git a/lazy/init_test.go b/lazy/init_test.go index 2051f6b1a..541b34b66 100644 --- a/lazy/init_test.go +++ b/lazy/init_test.go @@ -220,3 +220,22 @@ func TestInitBranchOrder(t *testing.T) { c.Assert(state.V2, qt.Equals, "ABAB") } + +// See issue 7043 +func TestResetError(t *testing.T) { + c := qt.New(t) + r := false + i := New().Add(func() (interface{}, error) { + if r { + return nil, nil + } + return nil, errors.New("r is false") + }) + _, err := i.Do() + c.Assert(err, qt.IsNotNil) + i.Reset() + r = true + _, err = i.Do() + c.Assert(err, qt.IsNil) + +}