{"record":{"id":"08f9693c293e997d","repo":"grafana/k6","slug":"unable-to-apply-threshold-s-over-metrics-reason","errorCode":null,"errorMessage":"unable to apply threshold %s over metrics; reason: %s is an invalid operator","messagePattern":"unable to apply threshold (.+?) over metrics; reason: (.+?) is an invalid operator","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"metrics/thresholds.go","lineNumber":71,"sourceCode":"\tswitch t.parsed.Operator {\n\tcase \">\":\n\t\tpasses = lhs > t.parsed.Value\n\tcase \">=\":\n\t\tpasses = lhs >= t.parsed.Value\n\tcase \"<=\":\n\t\tpasses = lhs <= t.parsed.Value\n\tcase \"<\":\n\t\tpasses = lhs < t.parsed.Value\n\tcase \"==\", \"===\":\n\t\t// Considering a sink always maps to float64 values,\n\t\t// strictly equal is equivalent to loosely equal\n\t\tpasses = lhs == t.parsed.Value\n\tcase \"!=\":\n\t\tpasses = lhs != t.parsed.Value\n\tdefault:\n\t\t// The parseThresholdExpression function should ensure that no invalid\n\t\t// operator gets through, but let's protect our future selves anyhow.\n\t\treturn false, fmt.Errorf(\"unable to apply threshold %s over metrics; \"+\n\t\t\t\"reason: %s is an invalid operator\",\n\t\t\tt.Source,\n\t\t\tt.parsed.Operator,\n\t\t)\n\t}\n\n\t// Perform the actual threshold verification\n\treturn passes, nil\n}\n\nfunc (t *Threshold) run(sinks map[string]float64) (bool, error) {\n\tpasses, err := t.runNoTaint(sinks)\n\tt.LastFailed = !passes\n\treturn passes, err\n}\n\ntype thresholdConfig struct {\n\tThreshold        string             `json:\"threshold\"`","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/thresholds.go#L53-L89","documentation":"Reached the default branch of the operator switch in Threshold.run: the parsed threshold expression carries an operator token that is not one of >, >=, <=, <, ==, ===, !=. The parser (parseThresholdExpression) should reject unknown operators earlier, so hitting this guard means a mismatch between the scanner's accepted operator set and this switch — effectively an internal invariant check.","triggerScenarios":"Thrown at metrics/thresholds.go:71 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the operator token lists (operatorTokens in thresholds_parser.go) exactly match the cases handled in Threshold.run","Fix the threshold expression to use a supported operator: >, >=, <=, <, ==, ===, !=","Report the inconsistency as a k6 bug if the expression was produced by the parser"],"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"}