nats-io/nats-server · error
expected 'cert_match' to be a valid non-empty string
Error message
expected 'cert_match' to be a valid non-empty string
What it means
ErrBadCertMatchField is a config-validation error raised when the cert_match option is not a string or is empty. cert_match holds the actual value (thumbprint, subject, etc.) used to find the certificate in the store, so it must be present and non-empty.
Source
Thrown at server/certstore/errors.go:69
ErrFailedX509Extract = errors.New("unable to extract x509 from certificate")
// ErrBadMatchByType represents unknown CERT_MATCH_BY passed
ErrBadMatchByType = errors.New("cert match by type not implemented")
// ErrBadCertStore represents unknown CERT_STORE passed
ErrBadCertStore = errors.New("cert store type not implemented")
// ErrConflictCertFileAndStore represents ambiguous configuration of both file and store
ErrConflictCertFileAndStore = errors.New("'cert_file' and 'cert_store' may not both be configured")
// ErrBadCertStoreField represents malformed cert_store option
ErrBadCertStoreField = errors.New("expected 'cert_store' to be a valid non-empty string")
// ErrBadCertMatchByField represents malformed cert_match_by option
ErrBadCertMatchByField = errors.New("expected 'cert_match_by' to be a valid non-empty string")
// ErrBadCertMatchField represents malformed cert_match option
ErrBadCertMatchField = errors.New("expected 'cert_match' to be a valid non-empty string")
// ErrBadCaCertMatchField represents malformed cert_match option
ErrBadCaCertMatchField = errors.New("expected 'ca_certs_match' to be a valid non-empty string array")
// ErrBadCertMatchSkipInvalidField represents malformed cert_match_skip_invalid option
ErrBadCertMatchSkipInvalidField = errors.New("expected 'cert_match_skip_invalid' to be a boolean")
// ErrOSNotCompatCertStore represents cert_store passed that exists but is not valid on current OS
ErrOSNotCompatCertStore = errors.New("cert_store not compatible with current operating system")
)
View on GitHub (pinned to 3a66a489d2)
Solutions
- Provide the actual match value, e.g. cert_match: "AB12CD34..." (thumbprint without spaces, correct case per the matcher).
- Verify any env substitution ($CERT_MATCH) resolves to a non-empty value in the server environment.
- Quote the value in YAML/JSON to keep it a string.
- Cross-check the value against `certutil -store My` output so it exactly matches an existing certificate.
Example fix
// before
cert_match: ${CERT_MATCH} # unset
// after
cert_match: "AB12CD34EF56..." Defensive patterns
Strategy: validation
Validate before calling
if s, ok := cfg.TLS.CertMatch.(string); !ok || s == "" {
return errors.New("cert_match must be a non-empty string")
} Type guard
func isBadCertMatchField(err error) bool { return errors.Is(err, certstore.ErrBadCertMatchField) } Try / catch
if ce, ok := err.(*server.configErr); ok && strings.Contains(ce.Error(), "cert_match") {
// supply the thumbprint/subject value
} Prevention
- Copy thumbprints exactly from certutil output, stripping spaces per matcher rules
- Fail deployment when template/env substitution leaves cert_match empty
- Re-check cert_match after every certificate renewal
When it happens
Trigger: server/opts.go:5294 — TLS config parsing: the cert_match value fails the string/non-empty check, returning &configErr{tk, certstore.ErrBadCertMatchField.Error()}; tc.CertMatch is only set once validation passes.
Common situations: Thumbprint pasted with surrounding whitespace removed wrongly, env var not set leaving an empty value, or config template rendering dropping the field.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- expected 'cert_store' to be a valid non-empty string
- expected 'cert_match_by' to be a valid non-empty string
- 'cert_file' and 'cert_store' may not both be configured
- invalid chain link
- ErrBadCryptoStoreProvider
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/a4d9ecbe4bd1bdfe.
Report an issue: GitHub.