7
7
"log/slog"
8
8
"reflect"
9
9
"slices"
10
+ "testing"
10
11
11
12
"github.com/benbjohnson/clock"
12
13
"github.com/cschleiden/go-workflows/backend"
@@ -185,6 +186,7 @@ func (e *executor) ExecuteTask(ctx context.Context, t *backend.WorkflowTask) (*E
185
186
if err != nil {
186
187
logger .Error ("Error while executing new events" , "error" , err )
187
188
189
+ // Transition workflow to error state
188
190
e .workflowCompleted (nil , err )
189
191
}
190
192
}
@@ -266,7 +268,6 @@ func (e *executor) executeNewEvents(newEvents []*history.Event) ([]*history.Even
266
268
}
267
269
268
270
if e .workflow .Completed () {
269
- // TODO: Is this too early? We haven't committed some of the commands
270
271
if e .workflowState .HasPendingFutures () {
271
272
var pending []string
272
273
pf := e .workflowState .PendingFutureNames ()
@@ -275,8 +276,11 @@ func (e *executor) executeNewEvents(newEvents []*history.Event) ([]*history.Even
275
276
}
276
277
slices .Sort (pending )
277
278
278
- 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
+ if testing .Testing () {
280
+ panic (fmt .Sprintf ("workflow completed, but there are still pending futures: %s" , pending ))
281
+ }
282
+
283
+ return newEvents , fmt .Errorf ("workflow completed, but there are still pending futures: %s" , pending )
280
284
}
281
285
282
286
if canErr , ok := e .workflow .Error ().(* continueasnew.Error ); ok {
0 commit comments