grafana/k6 · error

scenario name can't be empty

Error message

scenario name can't be empty

What it means

BaseConfig.Validate() performs just-in-case sanity checks on every scenario config; the first is that the scenario's Name is non-empty. Scenario names come from the keys of the options.scenarios object (or programmatic construction), so an empty-string key produces an anonymous config that metrics labels and the REST API could not reference, and validation collects this error.

Source

Thrown at lib/executor/base_config.go:54

	// TODO: future extensions like distribution, others?
}

// NewBaseConfig returns a default base config with the default values
func NewBaseConfig(name, configType string) BaseConfig {
	return BaseConfig{
		Name:         name,
		Type:         configType,
		GracefulStop: types.NewNullDuration(DefaultGracefulStopValue, false),
	}
}

// Validate checks some basic things like present name, type, and a positive start time
func (bc BaseConfig) Validate() (result []error) {
	// Some just-in-case checks, since those things are likely checked in other places or
	// even assigned by us:
	if bc.Name == "" {
		result = append(result, errors.New("scenario name can't be empty"))
	}
	if !scenarioNameWhitelist.MatchString(bc.Name) {
		result = append(result, errors.New(scenarioNameErr))
	}
	if bc.Exec.Valid && bc.Exec.String == "" {
		result = append(result, errors.New("exec value cannot be empty"))
	}
	if bc.Type == "" {
		result = append(result, errors.New("missing or empty type field"))
	}
	// The actually reasonable checks:
	if bc.StartTime.Duration < 0 {
		result = append(result, errors.New("the startTime can't be negative"))
	}
	if bc.GracefulStop.Duration < 0 {
		result = append(result, errors.New("the gracefulStop timeout can't be negative"))
	}
	return result

View on GitHub (pinned to 93accf6570)

Solutions

  1. Give every scenario a non-empty key: scenarios: { smoke: { executor: 'shared-iterations' } }
  2. Filter empty keys when generating scenarios from data: Object.fromEntries(Object.entries(map).filter(([k]) => k))
  3. If constructing BaseConfig in Go, always set Name (e.g. from the map key) before calling Validate()

Example fix

// before
export const options = { scenarios: { '': { executor: 'shared-iterations' } } };

// after
export const options = { scenarios: { smoke: { executor: 'shared-iterations' } } };
Defensive patterns

Strategy: validation

Validate before calling

// before exporting options, assert every scenario has a name
for (const name of Object.keys(scenarios)) {
  if (!name) throw new Error('scenario name can\u2019t be empty');
}
export const options = { scenarios };

Type guard

const hasValidScenarioNames = (scenarios) =>
  Object.keys(scenarios).every((k) => k.length > 0 && /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(k));

Prevention

When it happens

Trigger: Exporting options with scenarios: { '': { executor: 'shared-iterations', ... } }, or building a BaseConfig programmatically without setting Name before Validate().

Common situations: Generating scenarios from a config map/env prefix where one key is blank; YAML/JSON with an empty key; refactors that rename scenario keys and accidentally leave one empty; template strings producing '' as the key.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/5374a22a16ede8b9. Report an issue: GitHub.