Skip to content

Commit

Permalink
preprocessor: reset executor error state for each event in serve
Browse files Browse the repository at this point in the history
Per https://cuelang.org/issue/2826, currently if the serve mode of the
preprocessor sees an error, the preprocessor can never recover from that
error state. Even if an error in a page is fixed, the preprocessor
thinks that there is still an error and hence never transforms the fixed
page, hence the rendered HTML page (via Hugo) never updates.

This CL fixes a bug in the serve mode of the executor that did not reset
the error status after the handling of a watched event (or batch of
events).

Fixes cue-lang/cue#2826.

Preprocessor-No-Write-Cache: true
Signed-off-by: Paul Jolly <[email protected]>
Change-Id: I72231fd8df31945465eb81c48060c2612a0aa192
Dispatch-Trailer: {"type":"trybot","CL":1176998,"patchset":1,"ref":"refs/changes/98/1176998/1","targetBranch":"alpha"}
  • Loading branch information
myitcv authored and cueckoo committed Feb 18, 2024
1 parent eb2ecd6 commit 660e6b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/cmd/preprocessor/cmd/buffered_error_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ type errorContextBuffer struct {

var _ errorContext = (*errorContextBuffer)(nil)

func (e *errorContextBuffer) reset() error {
e.inError = false
e.log.Reset()
return nil
}

func (e *errorContextBuffer) isInError() bool {
return e.inError
}
Expand Down
20 changes: 19 additions & 1 deletion internal/cmd/preprocessor/cmd/error_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"io"

"cuelang.org/go/cue/errors"
"errors"
)

// errorContext is an error-aware logging interface embedded by types.
Expand All @@ -42,6 +42,10 @@ type errorContext interface {

// isInError returns the error state.
isInError() bool

// reset resets the error state. It is up to the caller to ensure that it
// is safe to call this from a race condition perspective.
reset() error
}

// errorContextWriter is a base implementation of errorContext
Expand All @@ -53,6 +57,20 @@ type errorContextWriter struct {
log io.Writer
}

func (e *errorContextWriter) reset() error {
// resetWriter is an io.Writer than also provides a Reset() method.
type resetWriter interface {
io.Writer
Reset() error
}

e.inError = false
if l, ok := e.log.(resetWriter); ok {
return l.Reset()
}
return nil
}

func (e *errorContextWriter) isInError() bool {
return e.inError
}
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/preprocessor/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ func (sc *serveContext) watcherEventLoop() {
// TODO: see the TODO agains the signal handling in (*executor).serve for ideas on
// how we do better tidy up.

// Reset the exeutor... because we either finished the first run or
// handled a watcher event
if err := sc.e.reset(); err != nil {
sc.e.debugf(sc.e.debugGeneral, "failed to reset executor: %v", err)
}

select {
case evs := <-sc.w.Events():
// Ignore if we only got events for the index file
Expand Down

0 comments on commit 660e6b7

Please sign in to comment.