{"record":{"id":"361a92de9b11150c","repo":"nats-io/nats-server","slug":"variable-reference-for-s-on-line-d-can-not-be","errorCode":null,"errorMessage":"variable reference for '%s' on line %d can not be found","messagePattern":"variable reference for '(.+?)' on line (.+?) can not be found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conf/parse.go","lineNumber":390,"sourceCode":"\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}\n\t\t} else {\n\t\t\tp.setValue(value)\n\t\t}\n\tcase itemInclude:","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/conf/parse.go#L372-L408","documentation":"A variable reference item was syntactically valid but lookupVariable could not find a value in any context map, in the config, or in the process environment (os.LookupEnv). The reference resolves to nothing, so parsing aborts with the reference name and line number.","triggerScenarios":"processItem (from parse) hits case itemVariable where lookupVariable returns found=false: the referenced key is absent from all pushed contexts, the included config, and the OS environment.","commonSituations":"Referencing an env var that was never exported (or only set in a different shell/CI stage), typo in the variable name, dependency on a variable set by a deployment manifest that isn't present locally, or referencing a config key defined after the reference in an include file.","solutions":["Define the referenced key in the config file or push it into the config context before parsing.","Export the environment variable before running the process (os.LookupEnv is consulted as fallback).","Fix typos in the reference name (error includes the name and line number).","Provide a default value at the call site instead of relying on an unset variable.","In CI/CD, ensure the variable is passed into the job/container environment."],"exampleFix":"// before (VAR unset)\nsecret = ${API_SECRET}\n// after\nexport API_SECRET=... # or define in config:\nAPI_SECRET = literal-value\nsecret = ${API_SECRET}","handlingStrategy":"try-catch","validationCode":"name := \"API_SECRET\"\nif os.LookupEnv(name) == nil {\n\treturn fmt.Errorf(\"required variable %s is not set\", name)\n}","typeGuard":null,"tryCatchPattern":"var perr interface{ }\nif err := parseConfig(); err != nil {\n\tif strings.Contains(err.Error(), \"can not be found\") {\n\t\t// resolve the missing variable or abort with a clear setup message\n\t\treturn fmt.Errorf(\"config setup incomplete: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Document and check all required env vars at process startup.","Provide defaults for optional variables.","Keep variable definitions before their references in include order.","Verify CI/CD passes the same env vars as local dev."],"tags":["config","variables","environment","missing-value"],"backgroundTag":"missing-env-var","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}