hashicorp/nomad · error

Could not find task named: %s, found: %s

Error message

Could not find task named: %s, found:
%s

What it means

`nomad alloc restart <alloc-id> -task <name>` validates the task name against the tasks of the allocation's task group. The group was found, but none of its tasks match the requested name, so the error lists all valid task names via formatList. This is a user-input error: the -task value doesn't correspond to any task in that group.

Source

Thrown at command/alloc_restart.go:179

	return 0
}

func validateTaskExistsInAllocation(taskName string, alloc *api.Allocation) error {
	tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
	if tg == nil {
		return fmt.Errorf("Could not find allocation task group: %s", alloc.TaskGroup)
	}

	foundTaskNames := make([]string, len(tg.Tasks))
	for i, task := range tg.Tasks {
		foundTaskNames[i] = task.Name
		if task.Name == taskName {
			return nil
		}
	}

	return fmt.Errorf("Could not find task named: %s, found:\n%s", taskName, formatList(foundTaskNames))
}

func (c *AllocRestartCommand) Synopsis() string {
	return "Restart a running allocation"
}

func (c *AllocRestartCommand) AutocompleteFlags() complete.Flags {
	return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
		complete.Flags{
			"-all-tasks": complete.PredictNothing,
			"-verbose":   complete.PredictNothing,
			"-task":      complete.PredictAnything,
		})
}

func (c *AllocRestartCommand) AutocompleteArgs() complete.Predictor {
	// Here we attempt to autocomplete allocations for any position of arg.
	// We should eventually try to auto complete the task name if the arg is

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Use the task names listed in the error message itself (the "found:" list) and re-run with a valid -task value.
  2. List current tasks with `nomad alloc status <alloc-id>` or `nomad job inspect <job>` and pick the correct one.
  3. Update automation/CI scripts to derive the task name dynamically from the allocation instead of hardcoding it.
  4. If the task should exist, check whether the allocation is from an old job version and target the newest allocation for the job.

Example fix

// before
nomad alloc restart 1f2a3b4c -task webapp
// Error: Could not find task named: webapp, found:\n  * web

// after
nomad alloc restart 1f2a3b4c -task web

// in scripts: resolve the task dynamically instead of hardcoding
alloc, _, _ := client.Allocations().Info(allocID, nil)
tg, _ := lookupAllocTask(alloc) // returns the single task's name when unambiguous
Defensive patterns

Strategy: validation

Validate before calling

tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if tg == nil { return fmt.Errorf("task group %q not found", alloc.TaskGroup) }
valid := map[string]bool{}
for _, t := range tg.Tasks { valid[t.Name] = true }
if !valid[taskName] {
    names := make([]string, 0, len(tg.Tasks))
    for _, t := range tg.Tasks { names = append(names, t.Name) }
    return fmt.Errorf("task %q invalid; valid tasks: %v", taskName, names)
}
return nil

Type guard

func taskExistsInAlloc(alloc *api.Allocation, taskName string) bool {
    tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
    if tg == nil { return false }
    for _, t := range tg.Tasks {
        if t.Name == taskName { return true }
    }
    return false
}

Try / catch

if err := validateTaskExistsInAllocation(taskName, alloc); err != nil {
    if strings.Contains(err.Error(), "Could not find task named") {
        // parse the "found:" list from the error and pick/confirm the right task,
        // or re-run `nomad alloc status <alloc-id>` to get current task names
        return fmt.Errorf("use a task from: %s (got %q)", extractFoundList(err), taskName)
    }
    return err
}

Prevention

When it happens

Trigger: Running `nomad alloc restart <alloc-id> -task foo` where the allocation's task group contains tasks other than "foo" — typical after a task rename in a newer job version, or supplying a task name from a different group/job.

Common situations: Copy-pasting a task name from an old job file after a rename (e.g. "webapp" → "web"); scripting restarts with a hardcoded task name that changed between deploys; confusing the task name with the task group name or the service name.

Related errors


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