grafana/k6 · error
error for stage
Error message
error for stage %d: %w
What it means
Wrapped error while parsing a --stage flag value in getOptions: the i-th stage string could not be unmarshalled by lib.Stage.UnmarshalText — the 'duration:ramp' style syntax is malformed. The index in the message identifies which --stage entry is at fault.
Solutions
- Use correct stage syntax, e.g. --stage 30s:10 or 1m:20
- Check the stage index in the message to find the offending flag value
- Fix the JSON/text stage definitions in options.stages in the script
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/cmd/options.go:114 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/91f7d82ad116ed9b.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cmd/options.go:123
NoConnectionReuse: getNullBool(flags, "no-connection-reuse"),
NoVUConnectionReuse: getNullBool(flags, "no-vu-connection-reuse"),
MinIterationDuration: getNullDuration(flags, "min-iteration-duration"),
Throw: getNullBool(flags, "throw"),
DiscardResponseBodies: getNullBool(flags, "discard-response-bodies"),
MetricSamplesBufferSize: null.NewInt(1000, false),
}
// Using Changed() because GetStringSlice() doesn't differentiate between empty and no value
if flags.Changed("stage") {
stageStrings, err := flags.GetStringSlice("stage")
if err != nil {
return opts, err
}
opts.Stages = []lib.Stage{}
for i, s := range stageStrings {
var stage lib.Stage
if err := stage.UnmarshalText([]byte(s)); err != nil {
return opts, fmt.Errorf("error for stage %d: %w", i, err)
}
if !stage.Duration.Valid {
return opts, fmt.Errorf("stage %d doesn't have a specified duration", i)
}
opts.Stages = append(opts.Stages, stage)
}
}
if flags.Changed("execution-segment") {
executionSegmentStr, err := flags.GetString("execution-segment")
if err != nil {
return opts, err
}
segment := new(lib.ExecutionSegment)
err = segment.UnmarshalText([]byte(executionSegmentStr))
if err != nil {
return opts, err
}View on GitHub (pinned to 8d06114777)