{"record":{"id":"9c2bce43fb2da5b8","repo":"grafana/k6","slug":"malformed-threshold-expression","errorCode":null,"errorMessage":"malformed threshold expression","messagePattern":"malformed threshold expression","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"metrics/thresholds_parser.go","lineNumber":152,"sourceCode":"\ttokenLooselyEqual,\n\ttokenBangEqual,\n}\n\n// scanThresholdExpression scans a threshold condition expression of the\n// form: `aggregation_method operator value`. An invalid or unknown operator\n// will produce an error. However, no assertions regarding\n// either the left-hand side aggregation method nor the right-hand\n// side value will be made: they will be returned as is, only trimmed from\n// their spaces.\nfunc scanThresholdExpression(input string) (string, string, string, error) {\n\tfor _, op := range operatorTokens {\n\t\tleft, right, _ := strings.Cut(input, op)\n\t\tif right != \"\" {\n\t\t\treturn strings.TrimSpace(left), op, strings.TrimSpace(right), nil\n\t\t}\n\t}\n\n\treturn \"\", \"\", \"\", fmt.Errorf(\"malformed threshold expression\")\n}\n\n// Define accepted threshold expression aggregation tokens\n// Percentile token `p(..)` is accepted too but handled separately.\nconst (\n\ttokenValue      = \"value\"\n\ttokenCount      = \"count\"\n\ttokenRate       = \"rate\"\n\ttokenAvg        = \"avg\"\n\ttokenMin        = \"min\"\n\ttokenMed        = \"med\"\n\ttokenMax        = \"max\"\n\ttokenPercentile = \"p\"\n)\n\n// aggregationMethodTokens defines the list of aggregation method\n// used in the parsing of threshold expressions.\n//","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/thresholds_parser.go#L134-L170","documentation":"scanThresholdExpression found no valid operator token in the input: none of the operatorTokens (>, >=, <=, <, ==, ===, !=) split the string into a non-empty left and right part. The expression is malformed at the top level — typically a missing operator or a dangling value.","triggerScenarios":"Thrown at metrics/thresholds_parser.go:152 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add a comparison operator to the threshold, e.g. 'avg>100'","Make sure both sides of the operator are non-empty","Verify the threshold key wasn't truncated or mis-quoted in the options"],"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"}