From 86ce5e088c418384eef96e4af644c1991e5f3413 Mon Sep 17 00:00:00 2001 From: lukema95 <867273263@qq.com> Date: Wed, 25 Dec 2024 00:33:54 +0800 Subject: [PATCH] refactor(engine): improve Engine.Start error handling --- execution/engine/engine.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/execution/engine/engine.go b/execution/engine/engine.go index 0a2d2e9fa9..b778a1bf63 100644 --- a/execution/engine/engine.go +++ b/execution/engine/engine.go @@ -22,6 +22,7 @@ package engine import ( "context" + "fmt" ctypes "github.com/berachain/beacon-kit/consensus-types/types" engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" @@ -58,17 +59,23 @@ func New( } } -// Start spawns any goroutines required by the service. -func (ee *Engine) Start( - ctx context.Context, -) error { +func (ee *Engine) Start(ctx context.Context) error { + errChan := make(chan error, 1) go func() { - // TODO: handle better - if err := ee.ec.Start(ctx); err != nil { - panic(err) - } + if err := ee.ec.Start(ctx); err != nil { + ee.logger.Error("engine client failed to start", "error", err) + errChan <- err + return + } + close(errChan) }() - return nil + + select { + case err := <-errChan: + return err + case <-ctx.Done(): + return fmt.Errorf("engine client start cancelled: %w", ctx.Err()) + } } // GetPayload returns the payload and blobs bundle for the given slot.