{"record":{"id":"faaa8af0a89c2254","repo":"grafana/k6","slug":"w-metric-q-lacks-a-closing-curly-brace-in-its-l","errorCode":null,"errorMessage":"%w, metric %q lacks a closing curly brace in its last position","messagePattern":"%w, metric %q lacks a closing curly brace in its last position","errorType":"validation","errorClass":"ErrMetricNameParsing","httpStatus":null,"severity":"error","filePath":"metrics/metric.go","lineNumber":121,"sourceCode":"\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\n\t// For each tag definition, ensure it is correctly formed\n\tfor i, t := range tags {\n\t\t_, value, _ := strings.Cut(t, \":\")\n\n\t\tif value == \"\" {\n\t\t\treturn \"\", nil, fmt.Errorf(\"%w, metric %q tag expression is malformed\", ErrMetricNameParsing, t)","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/metric.go#L103-L139","documentation":"Raised by ParseMetricName when a metric name with braces does not end with '}' — trailing characters follow the closing brace, so the tag expression cannot be cleanly extracted. Wraps the ErrMetricNameParsing sentinel.","triggerScenarios":"Thrown at metrics/metric.go:121 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["End the name with the closing brace, e.g. my_metric{tag:value}","Move any trailing content out of the metric name"],"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"}