From 1226caa4665715b191841c614bbbcae6446a683a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Mon, 16 Dec 2024 20:15:22 +0000 Subject: [PATCH] cdc_flow: cleanup error handling --- flow/workflows/cdc_flow.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/flow/workflows/cdc_flow.go b/flow/workflows/cdc_flow.go index 9358093b9d..a3764a6777 100644 --- a/flow/workflows/cdc_flow.go +++ b/flow/workflows/cdc_flow.go @@ -503,27 +503,22 @@ func CDCFlowWorkflow( } syncCtx := workflow.WithChildOptions(ctx, syncFlowOpts) - handleError := func(name string, err error) { - var panicErr *temporal.PanicError - if errors.As(err, &panicErr) { - logger.Error( - "panic in flow", - slog.String("name", name), - slog.Any("error", panicErr.Error()), - slog.String("stack", panicErr.StackTrace()), - ) - } else { - logger.Error("error in flow", slog.String("name", name), slog.Any("error", err)) - } - } - syncFlowFuture := workflow.ExecuteChildWorkflow(syncCtx, SyncFlowWorkflow, cfg, state.SyncFlowOptions) mainLoopSelector := workflow.NewNamedSelector(ctx, "MainLoop") mainLoopSelector.AddReceive(ctx.Done(), func(_ workflow.ReceiveChannel, _ bool) {}) mainLoopSelector.AddFuture(syncFlowFuture, func(f workflow.Future) { if err := f.Get(ctx, nil); err != nil { - handleError("sync", err) + var panicErr *temporal.PanicError + if errors.As(err, &panicErr) { + logger.Error( + "panic in sync flow", + slog.Any("error", panicErr.Error()), + slog.String("stack", panicErr.StackTrace()), + ) + } else { + logger.Error("error in sync flow", slog.Any("error", err)) + } } logger.Info("sync finished") @@ -554,8 +549,7 @@ func CDCFlowWorkflow( if state.ActiveSignal == model.PauseSignal || workflow.GetInfo(ctx).GetContinueAsNewSuggested() { restart = true if syncFlowFuture != nil { - err := model.SyncStopSignal.SignalChildWorkflow(ctx, syncFlowFuture, struct{}{}).Get(ctx, nil) - if err != nil { + if err := model.SyncStopSignal.SignalChildWorkflow(ctx, syncFlowFuture, struct{}{}).Get(ctx, nil); err != nil { logger.Warn("failed to send sync-stop, finishing", slog.Any("error", err)) finished = true }