{"record":{"id":"c6d19769ba651798","repo":"grafana/k6","slug":"invalidconfig-c6d197","errorCode":"InvalidConfig","errorMessage":"unable to validate threshold expressions; reason: %w","messagePattern":"unable to validate threshold expressions; reason: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"metrics/thresholds.go","lineNumber":247,"sourceCode":"\t\tt.parsed = parsed\n\t}\n\n\treturn nil\n}\n\n// ErrInvalidThreshold indicates a threshold is not valid\nvar ErrInvalidThreshold = errors.New(\"invalid threshold\")\n\n// Validate ensures a threshold definition is consistent with the metric it applies to.\n// Given a metric registry and a metric name to apply the expressions too, Validate will\n// assert that each threshold expression uses an aggregation method that's supported by the\n// provided metric. It returns an error otherwise.\n// Note that this function expects the passed in thresholds to have been parsed already, and\n// have their Parsed (ThresholdExpression) field already filled.\nfunc (ts *Thresholds) Validate(metricName string, r *Registry) error {\n\tparsedMetricName, _, err := ParseMetricName(metricName)\n\tif err != nil {\n\t\tparseErr := fmt.Errorf(\"unable to validate threshold expressions; reason: %w\", err)\n\t\treturn errext.WithExitCodeIfNone(parseErr, exitcodes.InvalidConfig)\n\t}\n\n\t// Obtain the metric the thresholds apply to from the registry.\n\t// if the metric doesn't exist, then we return an error indicating\n\t// the InvalidConfig exitcode should be used.\n\tmetric := r.Get(parsedMetricName)\n\tif metric == nil {\n\t\terr := fmt.Errorf(\"%w defined on %s; reason: no metric name %q found\", ErrInvalidThreshold, metricName, metricName)\n\t\treturn errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig)\n\t}\n\n\tfor _, threshold := range ts.Thresholds {\n\t\t// Return a digestable error if we attempt to validate a threshold\n\t\t// that hasn't been parsed yet.\n\t\tif threshold.parsed == nil {\n\t\t\tthresholdExpression, err := parseThresholdExpression(threshold.Source)\n\t\t\tif err != nil {","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/thresholds.go#L229-L265","documentation":"Wraps an error raised while Thresholds.Validate checks each threshold expression against a metric from the registry. It is a generic wrapper: the real cause (carried by %w) is typically a parse failure of a threshold expression during validation, meaning the expression string does not match the 'aggregation method operator value' grammar.","triggerScenarios":"Thrown at metrics/thresholds.go:247 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error to see which threshold expression failed to parse","Rewrite threshold expressions in the form 'method<op>value', e.g. 'p(95)<500' or 'rate<0.01'","Use only supported aggregation methods (avg, min, max, med, p(N), count, rate, value)"],"exampleFix":null,"handlingStrategy":"try-catch","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"}