Skip to content

Commit 03450b5

Browse files
authored
Explain shouldn't panic on invalid specs (#960)
* Explain shouldn't panic on invalid specs
1 parent 0ad973a commit 03450b5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

api/v1beta1/disruption_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,18 @@ func (s DisruptionSpec) DisruptionCount() int {
885885

886886
// Explain returns a string explanation of this disruption spec
887887
func (s DisruptionSpec) Explain() []string {
888+
if err := s.Validate(); err != nil {
889+
retErr := []string{"We were not able to explain this spec as it is not valid."}
890+
891+
if merr, ok := err.(*multierror.Error); ok {
892+
for _, e := range merr.Errors {
893+
retErr = append(retErr, e.Error())
894+
}
895+
}
896+
897+
return retErr
898+
}
899+
888900
var explanation []string
889901
explanation = append(explanation, "Here's our best explanation of what this spec will do when run:")
890902

0 commit comments

Comments
 (0)