Merge pull request #11 from sqshq/config_validation_for_absent_sample_script

Address crash reports: added validation to return user-friendly error if sampling script is not specified
This commit is contained in:
Alexander Lukyanchikov 2019-08-03 17:55:33 -04:00 committed by GitHub
commit dd6077d6a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -43,15 +43,16 @@ func (c *Config) validate() {
func validateItemsScripts(title string, items []Item) { func validateItemsScripts(title string, items []Item) {
for _, i := range items { for _, i := range items {
if i.InitScript != nil && i.MultiStepInitScript != nil { validateItemScripts(title, i)
validateItemScripts(title, i)
}
} }
} }
func validateItemScripts(title string, i Item) { func validateItemScripts(title string, i Item) {
if i.InitScript != nil && i.MultiStepInitScript != nil { if i.InitScript != nil && i.MultiStepInitScript != nil {
console.Exit(fmt.Sprintf("Config validation error: both init and multistep-init scripts are not allowed in '%s'", title)) console.Exit(fmt.Sprintf("Config validation error: both init and multistep-init scripts are not allowed for '%s'", title))
}
if i.SampleScript == nil {
console.Exit(fmt.Sprintf("Config validation error: sample script should be specified for '%s'", title))
} }
} }
@ -60,7 +61,7 @@ func validateLabelsUniqueness(title string, items []Item) {
for _, i := range items { for _, i := range items {
label := *i.Label label := *i.Label
if _, contains := labels[label]; contains { if _, contains := labels[label]; contains {
console.Exit(fmt.Sprintf("Config validation error: item labels should be unique. Please rename '%s' in '%s'", label, title)) console.Exit(fmt.Sprintf("Config validation error: item labels should be unique. Please rename '%s' for '%s'", label, title))
} }
labels[label] = true labels[label] = true
} }