{"record":{"id":"69e9e925114ceabe","repo":"hashicorp/nomad","slug":"unknown-task-name-q","errorCode":null,"errorMessage":"unknown task name %q","messagePattern":"unknown task name %q","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"client/alloc_endpoint.go","lineNumber":355,"sourceCode":"\t\tif !exec {\n\t\t\treturn nil, nstructs.ErrPermissionDenied\n\t\t}\n\t}\n\n\tallocState, err := a.c.GetAllocState(req.AllocID)\n\tif err != nil {\n\t\tcode := new(int64(500))\n\t\tif nstructs.IsErrUnknownAllocation(err) {\n\t\t\tcode = new(int64(404))\n\t\t}\n\n\t\treturn code, err\n\t}\n\n\t// Check that the task is there\n\ttaskState := allocState.TaskStates[req.Task]\n\tif taskState == nil {\n\t\treturn new(int64(400)), fmt.Errorf(\"unknown task name %q\", req.Task)\n\t}\n\n\tif taskState.StartedAt.IsZero() {\n\t\treturn new(int64(404)), fmt.Errorf(\"task %q not started yet.\", req.Task)\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\th := ar.GetTaskExecHandler(req.Task)\n\tif h == nil {\n\t\treturn new(int64(404)), fmt.Errorf(\"task %q is not running.\", req.Task)\n\t}\n\n\terr = h(ctx, req.Cmd, req.Tty, newExecStream(decoder, encoder))\n\tif err != nil {\n\t\tcode := new(int64(500))\n\t\treturn code, err","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/alloc_endpoint.go#L337-L373","documentation":"Nomad's client exec endpoint validates that the task name supplied in an exec request actually exists in the allocation's task state map before attempting to run a command. When req.Task does not match any task name in the allocation, execImpl returns HTTP 400 with this message. It is a request-validation error, not an internal failure.","triggerScenarios":"Calling the alloc exec API (via nomad alloc exec or the HTTP exec endpoint) with a task name that is not one of the tasks in the target allocation — e.g. a typo, a task from a different job, or a task that was removed in a later task-group version.","commonSituations":"Typo'd task names in scripts or CI; using the old task name after a job update renamed the task; exec'ing into a group-level allocation while specifying a task belonging to another group; autocomplete/scripts assuming a default task name.","solutions":["List the allocation's tasks with `nomad alloc status <alloc-id>` and use an exact task name in req.Task","Fix the task name typo in the command/script","If the task was renamed, redeploy scripts with the new name or pin to the old allocation","Verify you are exec'ing into the allocation that actually contains the task"],"exampleFix":"// before\nclient.Exec(allocID, \"sidecar\", []string{\"ls\"})\n// after\nalloc, _, _ := client.Allocations().Info(allocID, nil)\ntaskName := alloc.TaskGroup // or alloc.NamedTaskGroupStates key actually present\nclient.Exec(allocID, taskName, []string{\"ls\"})","handlingStrategy":"validation","validationCode":"alloc, _, err := client.Allocations().Info(allocID, nil)\nif err != nil { return err }\nts, ok := alloc.TaskStates[taskName]\nif !ok { return fmt.Errorf(\"alloc %s has no task %q\", allocID, taskName) }","typeGuard":"func hasTask(alloc *api.Allocation, task string) bool {\n  _, ok := alloc.TaskStates[task]\n  return ok\n}","tryCatchPattern":null,"preventionTips":["Derive task names from alloc.TaskStates rather than hardcoding","Validate task names in scripts with `nomad alloc status`","Use a single source of truth for task names shared between job spec and tooling"],"tags":["nomad","exec","validation","api"],"backgroundTag":"unknown-task-name","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}