From f97f5010e209fb9e7b7df0cf88b3d08ab2d2bccf Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 24 Nov 2025 19:41:48 -0500 Subject: [PATCH] Remove actors added through Add if they fail to initialize/config --- environment.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/environment.go b/environment.go index b3b1da7..0f6db1a 100644 --- a/environment.go +++ b/environment.go @@ -111,6 +111,10 @@ func (this *environment) Done(cause error) { // Add implements the package-level function [Add]. func (this *environment) Add(ctx context.Context, actors ...Actor) error { this.addToSets(actors...) + cleanUp := func() { + this.delFromSets(actors...) + } + initializable := make([]Initializable, 0, len(actors)) for _, actor := range actors { if actor, ok := actor.(Initializable); ok { @@ -122,12 +126,14 @@ func (this *environment) Add(ctx context.Context, actors ...Actor) error { if this.flags.crashOnError { panic(fmt.Sprint(err)) } + cleanUp() return err } for _, actor := range actors { if actor, ok := actor.(Configurable); ok { err := actor.Configure(this.conf) if err != nil { + cleanUp() return fmt.Errorf ( "could not apply configuration to %s: %w", actor.(Actor).Type(), err)