hashicorp/nomad · error
missing task names
Error message
missing task names
What it means
`verifiedTasks` requires at least one task name to verify. When the caller passes an empty taskNames slice, the helper short-circuits with "missing task names" because verifying zero tasks is a programming error rather than a meaningful request. This guards the task-level API surface (logs, exec, signals) from no-op calls.
Source
Thrown at client/client.go:3064
NodeSecret: c.secretNodeID(),
Region: c.Region(),
RPCFn: c.RPC,
CheckWatcher: serviceregistration.NewCheckWatcher(
c.logger, nsd.NewStatusGetter(c.checkStore),
),
}
c.nomadService = nsd.NewServiceRegistrationHandler(c.logger, &cfg)
}
// verifiedTasks asserts each task in taskNames actually exists in the given alloc,
// otherwise an error is returned.
func verifiedTasks(logger hclog.Logger, alloc *structs.Allocation, taskNames []string) ([]string, error) {
if alloc == nil {
return nil, fmt.Errorf("nil allocation")
}
if len(taskNames) == 0 {
return nil, fmt.Errorf("missing task names")
}
group := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if group == nil {
return nil, fmt.Errorf("group name in allocation is not present in job")
}
verifiedTasks := make([]string, 0, len(taskNames))
// confirm the requested task names actually exist in the allocation
for _, taskName := range taskNames {
if !taskIsPresent(taskName, group.Tasks) {
logger.Error("task not found in the allocation", "task_name", taskName)
return nil, fmt.Errorf("task %q not found in allocation", taskName)
}
verifiedTasks = append(verifiedTasks, taskName)
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Pass at least one valid task name in the request
- Default to the allocation's first (or declared) task when the caller provides none
- Validate task names in your client code before calling the Nomad client API
Example fix
// before
names := getRequestedTasks(req) // may be empty
verified, err := verifiedTasks(logger, alloc, names)
// after
names := getRequestedTasks(req)
if len(names) == 0 {
names = []string{defaultTaskName}
}
verified, err := verifiedTasks(logger, alloc, names) Defensive patterns
Strategy: validation
Validate before calling
if len(taskNames) == 0 {
return fmt.Errorf("at least one task name is required")
}
verified, err := verifiedTasks(logger, alloc, taskNames) Type guard
func hasTaskNames(names []string) bool {
return len(names) > 0
} Try / catch
if err := runTaskOp(alloc, tasks); err != nil {
if strings.Contains(err.Error(), "missing task names") {
// fall back to default task
}
} Prevention
- Default to the allocation's primary task when the caller supplies none
- Validate request bodies/CLI flags for the task parameter
- Never pass nil slices where a task list is expected
When it happens
Trigger: Calling a client task operation (e.g. allocation logs or exec against specific tasks) with an empty list of task names derived from user input, CLI flags, or an API request body that omitted the tasks parameter.
Common situations: HTTP API calls where the `task` query parameter was omitted; automation scripts that compute the task list from an empty environment section; tooling that passes nil slices after a failed lookup.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- task %q not found in allocation
- start_join is not supported for Nomad clients
- missing secret ID
- namespace cannot contain template delimiters or parenthesis
- no servers
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/5d9a24bbf74ee1d4.
Report an issue: GitHub.