From 67e2c0b83ccdc71f7098686d45b68eaf50814f65 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Thu, 12 Nov 2020 11:26:54 -0500 Subject: [PATCH] Add nullStep as return for multistep.If (#10247) This change introduces a new nullStep type that can be used in place of a nil step. This fixes an issue where multistep.If would return a nil step if the condition was not met causing a builder to crash when executed using `-on-error=ask` or `-on-error=abort`. Closes #10241 --- helper/multistep/if.go | 2 +- helper/multistep/multistep.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/helper/multistep/if.go b/helper/multistep/if.go index f485c50dc..f9705af62 100644 --- a/helper/multistep/if.go +++ b/helper/multistep/if.go @@ -3,7 +3,7 @@ package multistep // if returns step only if on is true. func If(on bool, step Step) Step { if on == false { - return nil + return &nullStep{} } return step } diff --git a/helper/multistep/multistep.go b/helper/multistep/multistep.go index a4629bacf..a3e427c0c 100644 --- a/helper/multistep/multistep.go +++ b/helper/multistep/multistep.go @@ -61,3 +61,11 @@ type Runner interface { // Run runs the steps with the given initial state. Run(context.Context, StateBag) } + +type nullStep struct{} + +func (s nullStep) Run(ctx context.Context, state StateBag) StepAction { + return ActionContinue +} + +func (s nullStep) Cleanup(state StateBag) {}