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
This commit is contained in:
Wilken Rivera 2020-11-12 11:26:54 -05:00 committed by GitHub
parent f44e912072
commit 67e2c0b83c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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
}

View File

@ -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) {}