hashicorp/nomad · error

namespace %s does not exist

Error message

namespace %s does not exist

What it means

namespaceNoAssociatedQuotasLocally looks up the namespace in the state snapshot to check whether a quota spec is attached. If the namespace record is absent, the check cannot proceed and it returns 'namespace %s does not exist'. This surfaces when a caller requests deletion of a namespace that was already removed or never created.

Source

Thrown at nomad/namespace_endpoint.go:307

		if raw == nil {
			break
		}

		v := raw.(*structs.VariableEncrypted)
		if v.VariableMetadata.Namespace == namespace {
			return false, nil
		}
	}

	return true, nil
}

// namespaceNoAssociatedQuotasLocally returns true if there are no quotas
// associated with this namespace in the local region
func (n *Namespace) namespaceNoAssociatedQuotasLocally(namespace string, snap *state.StateSnapshot) (bool, error) {
	ns, _ := snap.NamespaceByName(nil, namespace)
	if ns == nil {
		return false, fmt.Errorf("namespace %s does not exist", namespace)
	}
	if ns.Quota != "" {
		return false, nil
	}

	return true, nil
}

// namespaceTerminalJobsInRegion returns true if the namespace contains only
// terminal jobs in the given region.
func (n *Namespace) namespaceTerminalJobsInRegion(authToken, namespace, region string) (bool, error) {
	jobReq := &structs.JobListRequest{
		QueryOptions: structs.QueryOptions{
			Region:     region,
			Namespace:  namespace,
			AllowStale: false,
			AuthToken:  authToken,
		},

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Verify the namespace exists first (nomad namespace inspect <name> or GET /v1/namespace/<name>).
  2. Skip deletion for names that return not-found instead of failing.
  3. Fix the namespace name in the request/config if it was a typo.

Example fix

// before
client.Namespaces().Delete(&api.NamespaceDeleteRequest{Namespaces: names})
// after
var existing []string
for _, n := range names {
    if _, _, err := client.Namespaces().Info(n, nil); err == nil { existing = append(existing, n) }
}
client.Namespaces().Delete(&api.NamespaceDeleteRequest{Namespaces: existing})
Defensive patterns

Strategy: validation

Validate before calling

_, _, err := client.Namespaces().Info(name, nil)
if err != nil { return nil } // already gone; skip delete
_, err = client.Namespaces().Delete(&api.NamespaceDeleteRequest{Namespaces: []string{name}})

Type guard

func namespaceExists(c *api.Client, name string) bool {
    _, _, err := c.Namespaces().Info(name, nil)
    return err == nil
}

Prevention

When it happens

Trigger: Calling Namespace.Delete (or related validation) with a namespace name not present in the state store; double-delete after a first successful delete; a typo in the namespace name.

Common situations: Concurrent scripts/operators deleting the same namespace; stale configs or caches referencing a namespace deleted earlier; typos in IaC templates.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/844188148278b351. Report an issue: GitHub.