{"record":{"id":"8bad8c5719b05267","repo":"grafana/k6","slug":"w-metric-q-closing-curly-brace-appears-before-o","errorCode":null,"errorMessage":"%w, metric %q closing curly brace appears before opening one","messagePattern":"%w, metric %q closing curly brace appears before opening one","errorType":"validation","errorClass":"ErrMetricNameParsing","httpStatus":null,"severity":"error","filePath":"metrics/metric.go","lineNumber":115,"sourceCode":"\t// are present, thus the metric name only consists of a literal.\n\tif !containsOpeningToken && !containsClosingToken {\n\t\treturn name, nil, nil\n\t}\n\n\t// If the name contains an opening or closing token, but not\n\t// its counterpart, the expression is malformed.\n\tif (containsOpeningToken && !containsClosingToken) ||\n\t\t(!containsOpeningToken && containsClosingToken) {\n\t\treturn \"\", nil, fmt.Errorf(\n\t\t\t\"%w, metric %q has unmatched opening/close curly brace\",\n\t\t\tErrMetricNameParsing, name,\n\t\t)\n\t}\n\n\t// If the closing brace token appears before the opening one,\n\t// the expression is malformed\n\tif closingTokenPos < openingTokenPos {\n\t\treturn \"\", nil, fmt.Errorf(\"%w, metric %q closing curly brace appears before opening one\", ErrMetricNameParsing, name)\n\t}\n\n\t// If the last character is not a closing brace token,\n\t// the expression is malformed.\n\tif closingTokenPos != (len(name) - 1) {\n\t\terr := fmt.Errorf(\n\t\t\t\"%w, metric %q lacks a closing curly brace in its last position\",\n\t\t\tErrMetricNameParsing,\n\t\t\tname,\n\t\t)\n\t\treturn \"\", nil, err\n\t}\n\n\t// We already know the position of the opening and closing curly brace\n\t// tokens. Thus, we extract the string in between them, and split its\n\t// content to obtain the tags key values.\n\ttags := strings.Split(name[openingTokenPos+1:closingTokenPos], \",\")\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/metric.go#L97-L133","documentation":"Raised by ParseMetricName when a '}' appears before the matching '{' in a metric name with tag filters, making the expression malformed. Wraps the ErrMetricNameParsing sentinel.","triggerScenarios":"Thrown at metrics/metric.go:115 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Order the braces correctly: name first, then tags, e.g. my_metric{tag:value}"],"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-14T00:17:10.932Z"}