Skip to content

Commit

Permalink
Make errors with scenarios' name more clear (#3655)
Browse files Browse the repository at this point in the history
  • Loading branch information
joanlopez committed Mar 27, 2024
1 parent 4f38792 commit b17d645
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/executor/base_config.go
Expand Up @@ -18,9 +18,9 @@ import (
// TODO?: Discard? Or make this actually user-configurable somehow? hello #883...
var DefaultGracefulStopValue = 30 * time.Second //nolint:gochecknoglobals

var executorNameWhitelist = regexp.MustCompile(`^[0-9a-zA-Z_-]+$`)
var scenarioNameWhitelist = regexp.MustCompile(`^[0-9a-zA-Z_-]+$`)

const executorNameErr = "the executor name should contain only numbers, latin letters, underscores, and dashes"
const scenarioNameErr = "the scenario name should contain only numbers, latin letters, underscores, and dashes"

// BaseConfig contains the common config fields for all executors
type BaseConfig struct {
Expand Down Expand Up @@ -50,10 +50,10 @@ func (bc BaseConfig) Validate() (errors []error) {
// Some just-in-case checks, since those things are likely checked in other places or
// even assigned by us:
if bc.Name == "" {
errors = append(errors, fmt.Errorf("executor name can't be empty"))
errors = append(errors, fmt.Errorf("scenario name can't be empty"))
}
if !executorNameWhitelist.MatchString(bc.Name) {
errors = append(errors, fmt.Errorf(executorNameErr))
if !scenarioNameWhitelist.MatchString(bc.Name) {
errors = append(errors, fmt.Errorf(scenarioNameErr))
}
if bc.Exec.Valid && bc.Exec.String == "" {
errors = append(errors, fmt.Errorf("exec value cannot be empty"))
Expand All @@ -71,7 +71,7 @@ func (bc BaseConfig) Validate() (errors []error) {
return errors
}

// GetName returns the name of the executor.
// GetName returns the name of the scenario.
func (bc BaseConfig) GetName() string {
return bc.Name
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (bc BaseConfig) GetScenarioOptions() *lib.ScenarioOptions {
return bc.Options
}

// GetTags returns any custom tags configured for the executor.
// GetTags returns any custom tags configured for the scenario.
func (bc BaseConfig) GetTags() map[string]string {
return bc.Tags
}
Expand Down

0 comments on commit b17d645

Please sign in to comment.