hashicorp/nomad · error

Namespace %q matched no namespaces

Error message

Namespace %q matched no namespaces

What it means

getNamespace resolves a namespace argument against the Nomad API by prefix-listing namespaces. After the query, it inspects how many namespaces matched: if none did, it throws "Namespace %q matched no namespaces". This is a user-input resolution error — the namespace name given to the command does not correspond to any namespace registered in the cluster.

Source

Thrown at command/namespace_status.go:243

		fmt.Sprintf("Disabled Drivers|%s", disabled_drivers),
		fmt.Sprintf("Enabled Network Modes|%s", enabled_network_modes),
		fmt.Sprintf("Disabled Network Modes|%s", disabled_network_modes),
	}

	return formatKV(basic)
}

func getNamespace(client *api.Namespaces, ns string) (match *api.Namespace, possible []*api.Namespace, err error) {
	// Do a prefix lookup
	namespaces, _, err := client.PrefixList(ns, nil)
	if err != nil {
		return nil, nil, err
	}

	l := len(namespaces)
	switch {
	case l == 0:
		return nil, nil, fmt.Errorf("Namespace %q matched no namespaces", ns)
	case l == 1:
		return namespaces[0], nil, nil
	default:
		// search for an exact match in the returned namespaces
		for _, namespace := range namespaces {
			if namespace.Name == ns {
				return namespace, nil, nil
			}
		}
		// if not found, return the fuzzy matches.
		return nil, namespaces, nil
	}
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. List existing namespaces with `nomad namespace list` and confirm the exact name.
  2. Check you are targeting the intended cluster/region (NOMAD_ADDR, -region flags).
  3. Create the missing namespace: `nomad namespace apply <name>`.
  4. Re-run the command with the corrected namespace name.

Example fix

// before (shell)
nomad namespace status prod-web   // typo
// after
nomad namespace list              # find correct name
nomad namespace status prod-web-1
Defensive patterns

Strategy: validation

Validate before calling

// shell: verify before running
nomad namespace list | grep -qx "$NS" || { echo "namespace $NS not found"; exit 1; }
nomad namespace status "$NS"

Try / catch

// bash: capture and branch on the error message
if ! out=$(nomad namespace status "$NS" 2>&1); then
  case "$out" in *"matched no namespaces"*) nomad namespace apply "$NS" ;; esac
fi

Prevention

When it happens

Trigger: Running a command like `nomad namespace status <name>` (or any command routed through Run that resolves a namespace argument via getNamespace) where the PrefixList search for the given name returns zero namespaces.

Common situations: Typo in the namespace name; running against the wrong cluster/region (namespace exists elsewhere); the namespace was deleted or never created; using the fully-qualified or differently-cased name than what was registered.

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/a5972faa7a6bb636. Report an issue: GitHub.