hashicorp/nomad · error

context must be one of %v or 'all' for all contexts; got %q

Error message

context must be one of %v or 'all' for all contexts; got %q

What it means

In Nomad's open-source build, getEnterpriseResourceIter is a hook that should only be reached for enterprise-only search contexts. Reaching it means the requested context did not match any open-source context, so it always returns this error listing the valid contexts (allContexts). It is the terminal fallback of getResourceIter's context dispatch.

Source

Thrown at nomad/search_endpoint_ce.go:44

	// Handle cases where context name and state store table name do not match
	case structs.Variables:
		return state.TableVariables
	default:
		return string(ctx)
	}
}

// getEnterpriseMatch is a no-op in oss since there are no enterprise objects.
func getEnterpriseMatch(match any) (id string, ok bool) {
	return "", false
}

// getEnterpriseResourceIter is used to retrieve an iterator over an enterprise
// only table.
func getEnterpriseResourceIter(context structs.Context, _ *acl.ACL, namespace, prefix string, ws memdb.WatchSet, state *state.StateStore) (memdb.ResultIterator, error) {
	// If we have made it here then it is an error since we have exhausted all
	// open source contexts.
	return nil, fmt.Errorf("context must be one of %v or 'all' for all contexts; got %q", allContexts, context)
}

// getEnterpriseFuzzyResourceIter is used to retrieve an iterator over an enterprise
// only table.
func getEnterpriseFuzzyResourceIter(context structs.Context, _ *acl.ACL, _ string, _ memdb.WatchSet, _ *state.StateStore) (memdb.ResultIterator, error) {
	return nil, fmt.Errorf("context must be one of %v or 'all' for all contexts; got %q", allContexts, context)
}

func filteredSearchContextsEnt(aclObj *acl.ACL, namespace string, context structs.Context) bool {
	return true
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Use a valid OSS context from the error's list (volumes, allocation, deployment, task_group, evaluation, job, node, agents) or "all"
  2. Fix typos/casing in the Context field of the SearchRequest
  3. If enterprise contexts are required, run Nomad Enterprise instead of OSS

Example fix

// before
req := &api.SearchRequest{Context: "quotas"}
// after
req := &api.SearchRequest{Context: structs.ContextsJob} // or "all"
Defensive patterns

Strategy: validation

Validate before calling

validContexts := map[string]bool{
  "volumes": true, "allocation": true, "deployment": true,
  "task_group": true, "evaluation": true, "job": true,
  "node": true, "agents": true, "all": true,
}
if !validContexts[req.Context] {
    return fmt.Errorf("unsupported context %q for OSS Nomad", req.Context)
}

Type guard

func isValidSearchContext(c string) bool {
    switch structs.Context(c) {
    case structs.ContextsVolumes, structs.ContextsAllocation, structs.ContextsDeployment,
        structs.ContextsTaskGroup, structs.ContextsEvaluation, structs.ContextsJob,
        structs.ContextsNode, structs.ContextsAgent, structs.All:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: Calling the Search RPC with a Context value that is not one of the OSS contexts (e.g. an enterprise-only context like "quotas", "namespaces" enterprise variants, or any misspelled/invalid string) — or the string failing to equal any known context or 'all'.

Common situations: Typo in the context string sent by automation; tools written against Nomad Enterprise (contexts like 'multi-region' or quota contexts) pointed at an OSS cluster; stale SDK versions enumerating contexts the running server doesn't know.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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