From bd925d7fcdb7a0734fdfb6d8fb8db441ada43369 Mon Sep 17 00:00:00 2001 From: Jake Schuurmans Date: Wed, 28 Aug 2024 11:14:49 -0400 Subject: [PATCH] Fix a panic caused by setting interface to nil instead of a interface with a nil value --- internal/flipflop/handler.go | 2 +- internal/flipflop/task.go | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/internal/flipflop/handler.go b/internal/flipflop/handler.go index 0c7c2c3..e12becb 100644 --- a/internal/flipflop/handler.go +++ b/internal/flipflop/handler.go @@ -41,7 +41,7 @@ func (cth *ConditionTaskHandler) HandleTask(ctx context.Context, genTask *rctype cth.publisher = publisher // Ungeneric the task - task, err := NewTask(genTask, cth.cfg.FaultInjection) + task, err := NewTask(genTask) if err != nil { cth.logger.WithFields(logrus.Fields{ "conditionID": genTask.ID, diff --git a/internal/flipflop/task.go b/internal/flipflop/task.go index d450d16..34930bc 100644 --- a/internal/flipflop/task.go +++ b/internal/flipflop/task.go @@ -11,7 +11,7 @@ import ( type Task rctypes.Task[*rctypes.ServerControlTaskParameters, json.RawMessage] -func NewTask(task *rctypes.Task[any, any], faultInjection bool) (*Task, error) { +func NewTask(task *rctypes.Task[any, any]) (*Task, error) { paramsJSON, ok := task.Parameters.(json.RawMessage) if !ok { return nil, errInvalideConditionParams @@ -28,14 +28,9 @@ func NewTask(task *rctypes.Task[any, any], faultInjection bool) (*Task, error) { return nil, errors.Wrap(errTaskConv, err.Error()+": Task.Server") } - var fault interface{} - if faultInjection { - fault, err = copystructure.Copy(task.Fault) - if err != nil { - return nil, errors.Wrap(errTaskConv, err.Error()+": Task.Fault") - } - } else { - fault = nil + fault, err := copystructure.Copy(task.Fault) + if err != nil { + return nil, errors.Wrap(errTaskConv, err.Error()+": Task.Fault") } return &Task{