{"record":{"id":"4273f9cb72c8b10a","repo":"grafana/k6","slug":"the-duration-for-stage-d-can-t-be-negative","errorCode":null,"errorMessage":"the duration for stage %d can't be negative","messagePattern":"the duration for stage (.+?) can't be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/executor/helpers.go","lineNumber":48,"sourceCode":"\t\t}\n\t}\n\treturn result\n}\n\n// A helper function to avoid code duplication\nfunc validateStages(stages []Stage) []error {\n\tvar errors []error\n\tif len(stages) == 0 {\n\t\terrors = append(errors, fmt.Errorf(\"at least one stage has to be specified\"))\n\t\treturn errors\n\t}\n\n\tfor i, s := range stages {\n\t\tstageNum := i + 1\n\t\tif !s.Duration.Valid {\n\t\t\terrors = append(errors, fmt.Errorf(\"stage %d doesn't have a duration\", stageNum))\n\t\t} else if s.Duration.Duration < 0 {\n\t\t\terrors = append(errors, fmt.Errorf(\"the duration for stage %d can't be negative\", stageNum))\n\t\t}\n\t\tif !s.Target.Valid {\n\t\t\terrors = append(errors, fmt.Errorf(\"stage %d doesn't have a target\", stageNum))\n\t\t} else if s.Target.Int64 < 0 {\n\t\t\terrors = append(errors, fmt.Errorf(\"the target for stage %d can't be negative\", stageNum))\n\t\t}\n\t}\n\treturn errors\n}\n\n// handleInterrupt returns true if err is InterruptError and if so it\n// cancels the executor context passed with ctx.\nfunc handleInterrupt(ctx context.Context, err error) bool {\n\tif err != nil {\n\t\tif errext.IsInterruptError(err) {\n\t\t\texecution.AbortTestRun(ctx, err)\n\t\t\treturn true\n\t\t}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/lib/executor/helpers.go#L30-L66","documentation":"validateStages rejected a stage with a negative duration. Duration is set and valid, but a stage cannot last a negative amount of time; likely a typo or a computed value that went below zero.","triggerScenarios":"Thrown at lib/executor/helpers.go:48 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a non-negative duration string like '1m'","Check programmatically generated stage lists for sign errors"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}