grafana/k6 · error · ErrMetricNameParsing
%w, metric %q has unmatched opening/close curly brace
Error message
%w, metric %q has unmatched opening/close curly brace
What it means
Raised by ParseMetricName when a metric name with tag filters contains only one of the '{' or '}' brace tokens, so the expression cannot be split into metric name and tag list. Wraps the ErrMetricNameParsing sentinel for use with errors.Is.
Source
Thrown at metrics/metric.go:106
// Its first return value is the parsed metric name, second are parsed tags as as slice
// of "key:value" strings. On failure, it returns an error containing the `ErrMetricNameParsing` in its chain.
func ParseMetricName(name string) (string, []string, error) {
openingTokenPos := strings.IndexByte(name, '{')
closingTokenPos := strings.LastIndexByte(name, '}')
containsOpeningToken := openingTokenPos != -1
containsClosingToken := closingTokenPos != -1
// Neither the opening '{' token nor the closing '}' token
// are present, thus the metric name only consists of a literal.
if !containsOpeningToken && !containsClosingToken {
return name, nil, nil
}
// If the name contains an opening or closing token, but not
// its counterpart, the expression is malformed.
if (containsOpeningToken && !containsClosingToken) ||
(!containsOpeningToken && containsClosingToken) {
return "", nil, fmt.Errorf(
"%w, metric %q has unmatched opening/close curly brace",
ErrMetricNameParsing, name,
)
}
// If the closing brace token appears before the opening one,
// the expression is malformed
if closingTokenPos < openingTokenPos {
return "", nil, fmt.Errorf("%w, metric %q closing curly brace appears before opening one", ErrMetricNameParsing, name)
}
// If the last character is not a closing brace token,
// the expression is malformed.
if closingTokenPos != (len(name) - 1) {
err := fmt.Errorf(
"%w, metric %q lacks a closing curly brace in its last position",
ErrMetricNameParsing,
name,View on GitHub (pinned to 01ffac6f24)
Solutions
- Balance the braces, e.g. http_req_duration{status:200}
- Remove stray '{' or '}' characters from the metric name
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at metrics/metric.go:106 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/b768003dc0d9b3ae.
Report an issue: GitHub.