grafana/k6 · error · ErrMetricNameParsing
%w, metric %q closing curly brace appears before opening one
Error message
%w, metric %q closing curly brace appears before opening one
What it means
Raised by ParseMetricName when a '}' appears before the matching '{' in a metric name with tag filters, making the expression malformed. Wraps the ErrMetricNameParsing sentinel.
Source
Thrown at metrics/metric.go:115
// 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,
)
return "", nil, err
}
// We already know the position of the opening and closing curly brace
// tokens. Thus, we extract the string in between them, and split its
// content to obtain the tags key values.
tags := strings.Split(name[openingTokenPos+1:closingTokenPos], ",")
View on GitHub (pinned to 01ffac6f24)
Solutions
- Order the braces correctly: name first, then tags, e.g. my_metric{tag:value}
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at metrics/metric.go:115 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/8bad8c5719b05267.
Report an issue: GitHub.