{"record":{"id":"df722873456ffe81","repo":"hashicorp/nomad","slug":"namespace-not-found","errorCode":null,"errorMessage":"namespace not found","messagePattern":"namespace not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"nomad/state/state_store.go","lineNumber":7123,"sourceCode":"\t}\n\n\t// Reconcile changed quotas\n\treturn s.quotaReconcile(index, txn, ns.Quota, oldQuota)\n}\n\n// DeleteNamespaces is used to remove a set of namespaces\nfunc (s *StateStore) DeleteNamespaces(index uint64, names []string) error {\n\ttxn := s.db.WriteTxn(index)\n\tdefer txn.Abort()\n\n\tfor _, name := range names {\n\t\t// Lookup the namespace\n\t\texisting, err := txn.First(TableNamespaces, \"id\", name)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"namespace lookup failed: %v\", err)\n\t\t}\n\t\tif existing == nil {\n\t\t\treturn fmt.Errorf(\"namespace not found\")\n\t\t}\n\n\t\tns := existing.(*structs.Namespace)\n\t\tif ns.Name == structs.DefaultNamespace {\n\t\t\treturn fmt.Errorf(\"default namespace can not be deleted\")\n\t\t}\n\n\t\t// Ensure that the namespace doesn't have any non-terminal jobs\n\t\titer, err := s.jobsByNamespaceImpl(nil, name, txn, SortDefault)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tfor {\n\t\t\traw := iter.Next()\n\t\t\tif raw == nil {\n\t\t\t\tbreak\n\t\t\t}","sourceCodeStart":7105,"sourceCodeEnd":7141,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store.go#L7105-L7141","documentation":"NamespaceDelete requires the namespace to exist and rejects deleting the built-in default namespace. This error is returned when no namespace with the given name is found in the state store, so the delete is a no-op failure.","triggerScenarios":"`nomad namespace delete <name>` or Namespace.Delete API with a name that was never created or was already deleted.","commonSituations":"Typo in the namespace name; idempotent cleanup scripts running delete twice; wrong region/cluster context; namespace removed by another operator first.","solutions":["Verify the namespace exists with `nomad namespace list` and check spelling","Delete only if present in your script (ignore not-found for idempotency)","Confirm you are targeting the intended region/agent context","Use the default namespace check to avoid attempting to delete `default` (that raises a different error)"],"exampleFix":"// before\nnomad namespace delete prod  // fails if absent\n// after\nnomad namespace list | grep -q '^prod ' && nomad namespace delete prod || true","handlingStrategy":"try-catch","validationCode":"_, _, err := client.Namespaces().Info(name, nil)\nif err != nil { return nil // already absent; delete is a no-op }","typeGuard":"func namespaceExists(c *api.Client, name string) bool { _, _, err := c.Namespaces().Info(name, nil); return err == nil }","tryCatchPattern":"_, err := client.Namespaces().Delete(name, nil)\nif err != nil && strings.Contains(err.Error(), \"namespace not found\") {\n    return nil // idempotent delete\n} else if err != nil {\n    return err\n}","preventionTips":["Make delete scripts idempotent by treating not-found as success","Confirm namespace names via `nomad namespace list` before deleting","Set the correct region/context so you delete in the intended cluster"],"tags":["nomad","namespace","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-08T10:18:20.063Z"}