{"record":{"id":"c1de19126d001c8e","repo":"nats-io/nats-server","slug":"variable-reference-for-s-on-line-d-could-not-b","errorCode":null,"errorMessage":"variable reference for '%s' on line %d could not be parsed: %s","messagePattern":"variable reference for '(.+?)' on line (.+?) could not be parsed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conf/parse.go","lineNumber":386,"sourceCode":"\n\tcase itemDatetime:\n\t\tdt, err := time.Parse(\"2006-01-02T15:04:05Z\", it.val)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"expected Zulu formatted DateTime, but got '%s'\", it.val)\n\t\t}\n\t\tsetValue(it, dt)\n\tcase itemArrayStart:\n\t\tvar array = make([]any, 0)\n\t\tp.pushContext(array)\n\tcase itemArrayEnd:\n\t\tarray := p.ctx\n\t\tp.popContext()\n\t\tsetValue(it, array)\n\tcase itemVariable:\n\t\tvalue, found, err := p.lookupVariable(it.val)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"variable reference for '%s' on line %d could not be parsed: %s\",\n\t\t\t\tit.val, it.line, err)\n\t\t}\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"variable reference for '%s' on line %d can not be found\",\n\t\t\t\tit.val, it.line)\n\t\t}\n\n\t\tif p.pedantic {\n\t\t\tswitch tk := value.(type) {\n\t\t\tcase *token:\n\t\t\t\t// Mark the looked up variable as used, and make\n\t\t\t\t// the variable reference become handled as a token.\n\t\t\t\ttk.usedVariable = true\n\t\t\t\tp.setValue(&token{it, tk.Value(), false, fp})\n\t\t\tdefault:\n\t\t\t\t// Special case to add position context to bcrypt references.\n\t\t\t\tp.setValue(&token{it, value, false, fp})\n\t\t\t}","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/conf/parse.go#L368-L404","documentation":"A variable reference item was resolved via p.lookupVariable, which returned a non-nil error, meaning the reference string itself could not be parsed (e.g. malformed ${...} reference). The underlying parse error is included in the message.","triggerScenarios":"processItem (from parse) hits case itemVariable with a malformed reference in it.val (empty name, bad characters, nested/unclosed syntax), causing lookupVariable to return err.","commonSituations":"Typos in variable interpolation syntax, empty ${} references, references copied from shell with unsupported syntax ($VAR without braces if braces are required), or accidentally escaped/duplicated braces.","solutions":["Fix the variable reference syntax in the config to match the expected form (e.g. ${VAR} with a valid name).","Read the wrapped error in the message ('...: %s') to identify the exact parse problem.","Remove empty or malformed references and set the value literally.","Check for shell expansion mangling the reference before the config file was written."],"exampleFix":"// before\nendpoint = ${}\n// after\nendpoint = ${API_ENDPOINT}","handlingStrategy":"validation","validationCode":"refRe := regexp.MustCompile(`^\\$\\{[A-Za-z_][A-Za-z0-9_]*\\}$`)\nif !refRe.MatchString(ref) {\n\treturn fmt.Errorf(\"malformed variable reference %q\", ref)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use ${NAME} with a valid identifier; avoid empty references.","Beware of shell interpolation rewriting references when generating configs.","Grep generated configs for suspicious '${}' or '$' patterns."],"tags":["config","variables","interpolation","parsing"],"backgroundTag":"malformed-variable-reference","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}