{"record":{"id":"3f8ab108f6fcd134","repo":"nats-io/nats-server","slug":"expected-cert-match-by-to-be-a-valid-non-empty-s","errorCode":null,"errorMessage":"expected 'cert_match_by' to be a valid non-empty string","messagePattern":"expected 'cert_match_by' to be a valid non-empty string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/certstore/errors.go","lineNumber":66,"sourceCode":"\tErrFailedCertSearch = errors.New(\"unable to find certificate in store\")\n\n\t// ErrFailedX509Extract represents not being able to extract x509 certificate from found cert in store\n\tErrFailedX509Extract = errors.New(\"unable to extract x509 from certificate\")\n\n\t// ErrBadMatchByType represents unknown CERT_MATCH_BY passed\n\tErrBadMatchByType = errors.New(\"cert match by type not implemented\")\n\n\t// ErrBadCertStore represents unknown CERT_STORE passed\n\tErrBadCertStore = errors.New(\"cert store type not implemented\")\n\n\t// ErrConflictCertFileAndStore represents ambiguous configuration of both file and store\n\tErrConflictCertFileAndStore = errors.New(\"'cert_file' and 'cert_store' may not both be configured\")\n\n\t// ErrBadCertStoreField represents malformed cert_store option\n\tErrBadCertStoreField = errors.New(\"expected 'cert_store' to be a valid non-empty string\")\n\n\t// ErrBadCertMatchByField represents malformed cert_match_by option\n\tErrBadCertMatchByField = errors.New(\"expected 'cert_match_by' to be a valid non-empty string\")\n\n\t// ErrBadCertMatchField represents malformed cert_match option\n\tErrBadCertMatchField = errors.New(\"expected 'cert_match' to be a valid non-empty string\")\n\n\t// ErrBadCaCertMatchField represents malformed cert_match option\n\tErrBadCaCertMatchField = errors.New(\"expected 'ca_certs_match' to be a valid non-empty string array\")\n\n\t// ErrBadCertMatchSkipInvalidField represents malformed cert_match_skip_invalid option\n\tErrBadCertMatchSkipInvalidField = errors.New(\"expected 'cert_match_skip_invalid' to be a boolean\")\n\n\t// ErrOSNotCompatCertStore represents cert_store passed that exists but is not valid on current OS\n\tErrOSNotCompatCertStore = errors.New(\"cert_store not compatible with current operating system\")\n)\n","sourceCodeStart":48,"sourceCodeEnd":80,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/certstore/errors.go#L48-L80","documentation":"ErrBadCertMatchByField is a config-validation error raised when the cert_match_by option is not a string or is empty. cert_match_by selects how cert_match is interpreted (e.g. thumbprint vs subject), so it must be a valid non-empty string.","triggerScenarios":"server/opts.go:5284 — TLS config parsing: the cert_match_by value fails the string/non-empty check, producing &configErr{tk, certstore.ErrBadCertMatchByField.Error()} before ParseCertMatchBy runs.","commonSituations":"Empty cert_match_by left in the config after deleting cert_match, env substitution yielding nothing, or the value written as a YAML key/value mix-up.","solutions":["Set cert_match_by to a supported non-empty string such as \"thumbprint\" or \"subject\".","If using an env variable, confirm it is exported and non-empty for the server process.","Quote the value so YAML/JSON parsers keep it as a string.","Validate the config before deploy to catch the token/line number the configErr reports."],"exampleFix":"// before\ncert_match_by: \"\"\n// after\ncert_match_by: \"thumbprint\"","handlingStrategy":"validation","validationCode":"if s, ok := cfg.TLS.CertMatchBy.(string); !ok || s == \"\" {\n    return errors.New(\"cert_match_by must be a non-empty string\")\n}","typeGuard":"func isBadCertMatchByField(err error) bool { return errors.Is(err, certstore.ErrBadCertMatchByField) }","tryCatchPattern":"if ce, ok := err.(*server.configErr); ok && strings.Contains(ce.Error(), \"cert_match_by\") {\n    // set cert_match_by to a supported value\n}","preventionTips":["Always pair cert_match with an explicit cert_match_by","Verify env vars used in config are exported to the service","Validate configs in CI with a schema checker"],"tags":["configuration","tls","validation","certstore"],"backgroundTag":"invalid-config-value","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}