grafana/k6 · error · ErrMetricNameParsing

%w, metric %q lacks a closing curly brace in its last positi

Error message

%w, metric %q lacks a closing curly brace in its last position

What it means

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.

Source

Thrown at metrics/metric.go:121

	// 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], ",")

	// For each tag definition, ensure it is correctly formed
	for i, t := range tags {
		_, value, _ := strings.Cut(t, ":")

		if value == "" {
			return "", nil, fmt.Errorf("%w, metric %q tag expression is malformed", ErrMetricNameParsing, t)

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. End the name with the closing brace, e.g. my_metric{tag:value}
  2. Move any trailing content out of the metric name
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at metrics/metric.go:121 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/faaa8af0a89c2254. Report an issue: GitHub.