lazy: Reset error in Reset

To prevent sticky errors on server rebuilds.

Fixes #7043
Closes #9194
This commit is contained in:
Bjørn Erik Pedersen 2021-12-02 16:49:44 +01:00
parent 0eaaa8fee3
commit b10381fbe0
2 changed files with 20 additions and 0 deletions

View file

@ -136,6 +136,7 @@ func (ini *Init) shouldInitialize() bool {
// Reset resets the current and all its dependencies. // Reset resets the current and all its dependencies.
func (ini *Init) Reset() { func (ini *Init) Reset() {
mu := ini.init.ResetWithLock() mu := ini.init.ResetWithLock()
ini.err = nil
defer mu.Unlock() defer mu.Unlock()
for _, d := range ini.children { for _, d := range ini.children {
d.Reset() d.Reset()

View file

@ -220,3 +220,22 @@ func TestInitBranchOrder(t *testing.T) {
c.Assert(state.V2, qt.Equals, "ABAB") 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)
}