Skip to content

Commit f06c658

Browse files
committed
Do not panic at runtime for pending futures
1 parent 8757db2 commit f06c658

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/workflow/executor.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log/slog"
88
"reflect"
99
"slices"
10+
"testing"
1011

1112
"github.com/benbjohnson/clock"
1213
"github.com/cschleiden/go-workflows/backend"
@@ -266,7 +267,6 @@ func (e *executor) executeNewEvents(newEvents []*history.Event) ([]*history.Even
266267
}
267268

268269
if e.workflow.Completed() {
269-
// TODO: Is this too early? We haven't committed some of the commands
270270
if e.workflowState.HasPendingFutures() {
271271
var pending []string
272272
pf := e.workflowState.PendingFutureNames()
@@ -276,7 +276,15 @@ func (e *executor) executeNewEvents(newEvents []*history.Event) ([]*history.Even
276276
slices.Sort(pending)
277277

278278
e.logger.Error("workflow completed, but there are still pending futures", "pending", pending)
279-
panic(fmt.Sprintf("workflow completed, but there are still pending futures: %s", pending))
279+
280+
// Transition workflow to error state
281+
e.workflowCompleted(nil, fmt.Errorf("workflow completed, but there are still pending futures: %s", pending))
282+
283+
if testing.Testing() {
284+
panic(fmt.Sprintf("workflow completed, but there are still pending futures: %s", pending))
285+
}
286+
287+
return newEvents, nil
280288
}
281289

282290
if canErr, ok := e.workflow.Error().(*continueasnew.Error); ok {

0 commit comments

Comments
 (0)