aboutsummaryrefslogtreecommitdiffhomepage
path: root/lazy
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2021-12-02 16:49:44 +0100
committerBjørn Erik Pedersen <[email protected]>2021-12-02 18:06:19 +0100
commitb10381fbe0512a4c2081f7aa5ec97bd74c9f5c50 (patch)
tree2426e5ffc4002fb56033d883c6538ab8e001a6f1 /lazy
parent0eaaa8fee37068bfc8ecfb760f770ecc9a7af22a (diff)
downloadhugo-b10381fbe0512a4c2081f7aa5ec97bd74c9f5c50.tar.gz
hugo-b10381fbe0512a4c2081f7aa5ec97bd74c9f5c50.zip
lazy: Reset error in Reset
To prevent sticky errors on server rebuilds. Fixes #7043 Closes #9194
Diffstat (limited to 'lazy')
-rw-r--r--lazy/init.go1
-rw-r--r--lazy/init_test.go19
2 files changed, 20 insertions, 0 deletions
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)
+
+}