VictoriaMetrics/VictoriaMetrics · error

cannot parse headers: %w

Error message

cannot parse headers: %w

What it means

Returned by authContext.setHeaders/Config setup in lib/promauth when parseHeaders fails to parse the static HTTP headers map given in opts.Headers. It fires on invalid header syntax in the scrape/auth config (e.g. malformed header name/value); the wrapped error details the offending entry.

Source

Thrown at lib/promauth/config.go:749

		actx.mustInitFromBearerToken(opts.BearerToken)
	}
	if opts.OAuth2 != nil {
		if actx.getAuthHeader != nil {
			return nil, fmt.Errorf("cannot simultaneously use `authorization`, `basic_auth, `bearer_token` and `oauth2`")
		}
		if err := actx.initFromOAuth2Config(baseDir, opts.OAuth2); err != nil {
			return nil, fmt.Errorf("cannot initialize oauth2: %w", err)
		}
	}
	var tctx tlsContext
	if opts.TLSConfig != nil {
		if err := tctx.initFromTLSConfig(baseDir, opts.TLSConfig); err != nil {
			return nil, fmt.Errorf("cannot initialize tls: %w", err)
		}
	}
	headers, err := parseHeaders(opts.Headers)
	if err != nil {
		return nil, fmt.Errorf("cannot parse headers: %w", err)
	}
	hd := xxhash.New()
	for _, kv := range headers {
		_, _ = hd.Write([]byte(kv.key))
		_, _ = hd.Write([]byte("="))
		_, _ = hd.Write([]byte(kv.value))
		_, _ = hd.Write([]byte(","))
	}
	headersDigest := fmt.Sprintf("digest(headers)=%d", hd.Sum64())

	ac := &Config{
		tlsServerName:         tctx.serverName,
		tlsInsecureSkipVerify: tctx.insecureSkipVerify,
		tlsMinVersion:         tctx.minVersion,

		getTLSRootCA:    tctx.getTLSRootCA,
		tlsRootCADigest: tctx.tlsRootCADigest,

View on GitHub (pinned to 5079fb58f1)

Solutions

  1. Read the wrapped error to find which header entry is invalid
  2. Format every `headers` entry as `"Name: value"` with a colon separator
  3. Remove or fix the offending header entry and reload the config
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at lib/promauth/config.go:749 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03). Data as JSON: /api/errors/5acedca1b68c52b8. Report an issue: GitHub.