{"record":{"id":"a589b6c08cb148bf","repo":"hashicorp/nomad","slug":"missing-namespace","errorCode":null,"errorMessage":"missing namespace","messagePattern":"missing namespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/variables.go","lineNumber":72,"sourceCode":"\n\t// minVariableLockTTL and maxVariableLockTTL determine the range of valid durations for the\n\t// TTL on a lock.They come from the experience on Consul.\n\tminVariableLockTTL = 10 * time.Second\n\tmaxVariableLockTTL = 24 * time.Hour\n\n\t// defaultLockTTL is the default value used to maintain a lock before it needs to\n\t// be renewed. The actual value comes from the experience with Consul.\n\tdefaultLockTTL = 15 * time.Second\n\n\t// defaultLockDelay is the default a lock will be blocked after the TTL\n\t// went by without any renews. It is intended to prevent split brain situations.\n\t// The actual value comes from the experience with Consul.\n\tdefaultLockDelay = 15 * time.Second\n)\n\nvar (\n\terrNoPath             = errors.New(\"missing path\")\n\terrNoNamespace        = errors.New(\"missing namespace\")\n\terrNoLock             = errors.New(\"missing lock ID\")\n\terrWildCardNamespace  = errors.New(\"can not target wildcard (\\\"*\\\")namespace\")\n\terrQuotaExhausted     = errors.New(\"variables are limited to 64KiB in total size\")\n\terrNegativeDelayOrTTL = errors.New(\"Lock delay and TTL must be positive\")\n\terrInvalidTTL         = errors.New(\"TTL must be between 10 seconds and 24 hours\")\n)\n\n// VariableMetadata is the metadata envelope for a Variable, it is the list\n// object and is shared data between an VariableEncrypted and a\n// VariableDecrypted object.\ntype VariableMetadata struct {\n\tNamespace string\n\tPath      string\n\n\t// Lock represents a variable which is used for locking functionality.\n\tLock *VariableLock `json:\",omitempty\"`\n\n\tCreateIndex uint64","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/variables.go#L54-L90","documentation":"errNoNamespace is the sentinel error \"missing namespace\" in Nomad's structs package. Every variable lives in a namespace, and validation expects Namespace to be set (Canonicalize normally fills it with \"default\"); an empty namespace after canonicalization means the request was malformed and is rejected.","triggerScenarios":"Submitting a variable payload whose Namespace field is the empty string and bypassing or preceding canonicalization; constructing structs.Variable or VariableDecrypted in code/tests without setting Namespace before Validate.","commonSituations":"Raw API calls to /v1/var omitting the Namespace field; SDK/tooling that copies only path and items; hitting the validation path before Canonicalize() has had a chance to default the namespace.","solutions":["Set Namespace explicitly in the variable payload (e.g. \"default\") before submitting.","Call Canonicalize() on the Variable struct before Validate so the namespace is defaulted.","If using the CLI, ensure the -namespace flag or namespace context is set appropriately."],"exampleFix":"// before\nv := &structs.Variable{Path: \"a/b\"}\n// after\nv := &structs.Variable{Path: \"a/b\", Namespace: \"default\"}","handlingStrategy":"validation","validationCode":"if v.Namespace == \"\" {\n\tv.Namespace = \"default\"\n}","typeGuard":"func hasNamespace(v *structs.Variable) bool { return v != nil && v.Namespace != \"\" }","tryCatchPattern":"if errors.Is(err, structs.ErrNoNamespace) {\n\tv.Canonicalize() // defaults namespace\n\terr = v.Validate()\n}","preventionTips":["Call Canonicalize() before Validate() on variable structs","Include the Namespace field in all raw API payloads","Set -namespace or the agent namespace explicitly in automation"],"tags":["nomad","variables","validation","namespaces"],"backgroundTag":"missing-required-argument","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}