Skip to content

Commit

Permalink
lazy: Reset error in Reset
Browse files Browse the repository at this point in the history
To prevent sticky errors on server rebuilds.

Fixes #7043
Closes #9194
  • Loading branch information
bep committed Dec 2, 2021
1 parent 0eaaa8f commit b10381f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions lazy/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions lazy/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

0 comments on commit b10381f

Please sign in to comment.