{"record":{"id":"b1a4e33f6f61a0f4","repo":"hashicorp/nomad","slug":"variable-doesn-t-exist","errorCode":null,"errorMessage":"variable doesn't exist","messagePattern":"variable doesn't exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/state/state_store_variables.go","lineNumber":17,"sourceCode":"// Copyright IBM Corp. 2015, 2026\n// SPDX-License-Identifier: BUSL-1.1\n\npackage state\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"math\"\n\n\t\"github.com/hashicorp/go-memdb\"\n\t\"github.com/hashicorp/nomad/nomad/structs\"\n)\n\nvar (\n\terrVarAlreadyLocked = errors.New(\"variable already holds a lock\")\n\terrVarNotFound      = errors.New(\"variable doesn't exist\")\n\terrLockNotFound     = errors.New(\"variable doesn't hold a lock\")\n)\n\n// Variables queries all the variables and is used only for\n// snapshot/restore and key rotation\nfunc (s *StateStore) Variables(ws memdb.WatchSet) (memdb.ResultIterator, error) {\n\ttxn := s.db.ReadTxn()\n\n\titer, err := txn.Get(TableVariables, indexID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tws.Add(iter.WatchCh())\n\treturn iter, nil\n}\n\n// GetVariablesByNamespace returns an iterator that contains all","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store_variables.go#L1-L35","documentation":"errVarNotFound is the sentinel for variable path lookups that miss in the state store. It is returned by operations such as VarLockRelease and RenewLock when the variable record (VariableEncrypted) for the given path cannot be found, and by the write path (state_store_variables.go:537) when an operation targets a nonexistent variable. Callers map it to a 404-class RPC error.","triggerScenarios":"nomad var unlock/purge or lock renewal (RenewLock) on a path that has no stored variable; test table lookUpPath \"fake/path/\" style misses; using a path with wrong namespace; the variable was deleted concurrently between listing and acting on it.","commonSituations":"Typos in variable paths (paths are hierarchical keys like secret/app/config); wrong -namespace since variables are namespace-scoped; scripts unlocking variables that were already purged; expired variables removed by GC between calls.","solutions":["List variables (nomad var list -namespace <ns>) to confirm the exact path and namespace before lock/release operations.","Correct the path spelling and namespace in the client call.","Treat not-found as success in unlock/purge cleanup code paths since the target state already holds.","Re-create the variable if it was deleted unintentionally (nomad var put)."],"exampleFix":"// before: renew on a wrong path\n_, err := client.Variables().RenewLock(\"secret/app/db\", writeOpts)\n// after: verify existence first\n_, _, err := client.Variables().Read(\"secret/app/db\", nil)\nif err != nil { return fmt.Errorf(\"variable missing: %w\", err) }\n_, err = client.Variables().RenewLock(\"secret/app/db\", writeOpts)","handlingStrategy":"validation","validationCode":"// confirm the variable path and namespace before lock/release ops\n_, _, err := client.Variables().Read(path, &api.QueryOptions{Namespace: ns})\nif err != nil {\n    return fmt.Errorf(\"variable %s/%s does not exist\", ns, path)\n}","typeGuard":null,"tryCatchPattern":"_, err := client.Variables().RenewLock(path, writeOpts)\nif err != nil && strings.Contains(err.Error(), \"doesn't exist\") {\n    return nil // treat as already-purged for cleanup paths\n}","preventionTips":["Build paths from constants/templates, not string concatenation of user input.","Always scope variable operations with the right namespace.","List variables (`nomad var list`) to verify paths in interactive use.","Handle concurrent deletion between read and lock/release gracefully."],"tags":["nomad","variables","not-found","state-store"],"backgroundTag":"resource-not-found","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}