66 "fmt"
77 "log/slog"
88 "reflect"
9+ "slices"
910
1011 "github.com/benbjohnson/clock"
1112 "github.com/cschleiden/go-workflows/backend"
@@ -264,8 +265,15 @@ func (e *executor) executeNewEvents(newEvents []*history.Event) ([]*history.Even
264265 if e .workflow .Completed () {
265266 // TODO: Is this too early? We haven't committed some of the commands
266267 if e .workflowState .HasPendingFutures () {
267- e .logger .Error ("workflow completed, but there are still pending futures" )
268- panic ("workflow completed, but there are still pending futures" )
268+ var pending []string
269+ pf := e .workflowState .PendingFutureNames ()
270+ for id , name := range pf {
271+ pending = append (pending , fmt .Sprintf ("%d-%s" , id , name ))
272+ }
273+ slices .Sort (pending )
274+
275+ e .logger .Error ("workflow completed, but there are still pending futures" , "pending" , pending )
276+ panic (fmt .Sprintf ("workflow completed, but there are still pending futures: %s" , pending ))
269277 }
270278
271279 if canErr , ok := e .workflow .Error ().(* continueasnew.Error ); ok {
@@ -411,7 +419,7 @@ func (e *executor) handleActivityCompleted(event *history.Event, a *history.Acti
411419 return fmt .Errorf ("could not find pending future for activity completion" )
412420 }
413421
414- err := f (a .Result , nil )
422+ err := f . Set (a .Result , nil )
415423 if err != nil {
416424 return fmt .Errorf ("setting activity completed result: %w" , err )
417425 }
@@ -440,7 +448,7 @@ func (e *executor) handleActivityFailed(event *history.Event, a *history.Activit
440448 }
441449
442450 actErr := workflowerrors .ToError (a .Error )
443- if err := f (nil , actErr ); err != nil {
451+ if err := f . Set (nil , actErr ); err != nil {
444452 return fmt .Errorf ("setting activity failed result: %w" , err )
445453 }
446454
@@ -483,7 +491,7 @@ func (e *executor) handleTimerFired(event *history.Event, a *history.TimerFiredA
483491 return nil
484492 }
485493
486- if err := f (nil , nil ); err != nil {
494+ if err := f . Set (nil , nil ); err != nil {
487495 return fmt .Errorf ("setting timer fired result: %w" , err )
488496 }
489497
@@ -523,7 +531,7 @@ func (e *executor) handleTimerCanceled(event *history.Event, a *history.TimerCan
523531 return nil
524532 }
525533
526- if err := f (nil , sync .Canceled ); err != nil {
534+ if err := f . Set (nil , sync .Canceled ); err != nil {
527535 return fmt .Errorf ("setting timer canceled result: %w" , err )
528536 }
529537
@@ -580,7 +588,7 @@ func (e *executor) handleSubWorkflowFailed(event *history.Event, a *history.SubW
580588
581589 wfErr := workflowerrors .ToError (a .Error )
582590
583- if err := f (nil , wfErr ); err != nil {
591+ if err := f . Set (nil , wfErr ); err != nil {
584592 return fmt .Errorf ("setting sub workflow failed result: %w" , err )
585593 }
586594
@@ -606,7 +614,7 @@ func (e *executor) handleSubWorkflowCompleted(event *history.Event, a *history.S
606614 return errors .New ("no pending future found for sub workflow completed event" )
607615 }
608616
609- if err := f (a .Result , nil ); err != nil {
617+ if err := f . Set (a .Result , nil ); err != nil {
610618 return fmt .Errorf ("setting sub workflow completed result: %w" , err )
611619 }
612620
@@ -651,7 +659,7 @@ func (e *executor) handleSideEffectResult(event *history.Event, a *history.SideE
651659 return errors .New ("no pending future found for side effect result event" )
652660 }
653661
654- if err := f (a .Result , nil ); err != nil {
662+ if err := f . Set (a .Result , nil ); err != nil {
655663 return fmt .Errorf ("setting side effect result result: %w" , err )
656664 }
657665
0 commit comments