From: Bjørn Erik Pedersen Date: Thu, 2 Dec 2021 15:49:44 +0000 (+0100) Subject: lazy: Reset error in Reset X-Git-Tag: v0.90.0~18 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b10381fbe0512a4c2081f7aa5ec97bd74c9f5c50;p=brevno-suite%2Fhugo lazy: Reset error in Reset To prevent sticky errors on server rebuilds. Fixes #7043 Closes #9194 --- diff --git a/lazy/init.go b/lazy/init.go index e2e70072..6dff0c98 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 2051f6b1..541b34b6 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) + +}