{"record":{"id":"a50bf9090b370a2d","repo":"hashicorp/nomad","slug":"allocation-q-is-running-the-following-tasks","errorCode":null,"errorMessage":"Allocation %q is running the following tasks:\n  * %s\n\nPlease specify the task.","messagePattern":"Allocation %q is running the following tasks:\n  \\* (.+?)\n\nPlease specify the task\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/alloc_logs.go","lineNumber":440,"sourceCode":"}\n\nfunc lookupAllocTask(alloc *api.Allocation) (string, error) {\n\ttg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)\n\tif tg == nil {\n\t\treturn \"\", fmt.Errorf(\"Could not find allocation task group: %s\", alloc.TaskGroup)\n\t}\n\n\tif len(tg.Tasks) == 1 {\n\t\treturn tg.Tasks[0].Name, nil\n\t}\n\n\tvar errStr strings.Builder\n\tfmt.Fprintf(&errStr, \"Allocation %q is running the following tasks:\\n\", limit(alloc.ID, shortId))\n\tfor _, t := range tg.Tasks {\n\t\tfmt.Fprintf(&errStr, \"  * %s\\n\", t.Name)\n\t}\n\tfmt.Fprintf(&errStr, \"\\nPlease specify the task.\")\n\treturn \"\", errors.New(errStr.String())\n}\n","sourceCodeStart":422,"sourceCodeEnd":442,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/alloc_logs.go#L422-L442","documentation":"When `nomad alloc logs` is pointed at an allocation running multiple tasks without a -task specified, Nomad cannot guess which task's logs to fetch. lookupAllocTask enumerates the job's task group and returns this error listing every task so the user can pick one.","triggerScenarios":"Running `nomad alloc logs <alloc-id>` where the allocation's task group has more than one task and no -task flag is given.","commonSituations":"Multi-task jobs (sidecar + app), copy-pasted single-task-era commands, scripts that omit -task assuming one task per group.","solutions":["Add the -task flag: `nomad alloc logs -task app <alloc-id>`.","Run `nomad job inspect <job>` or `nomad alloc status <alloc>` to list the tasks first, then choose one.","Update scripts to always pass -task when targeting multi-task job groups."],"exampleFix":"// before\n$ nomad alloc logs 1f2b3c4d\n// after\n$ nomad alloc logs -task web 1f2b3c4d","handlingStrategy":"validation","validationCode":"status, _, err := client.Allocations().Info(allocID, nil)\nif err == nil && status.TaskGroup != \"\" {\n    job, _, _ := client.Jobs().Info(status.JobID, nil)\n    if job != nil && len(job.TaskGroups[0].Tasks) > 1 && taskFlag == \"\" {\n        return errors.New(\"multi-task alloc: pass -task\")\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := allocLogs(); err != nil && strings.Contains(err.Error(), \"Please specify the task\") {\n    // parse listed task names from the error and re-run with -task\n}","preventionTips":["Always pass -task for allocations from multi-task job groups.","Use `nomad alloc status` to enumerate tasks before fetching logs.","Parameterize task name in log-collection scripts."],"tags":["cli","logs","task-selection","argument-required"],"backgroundTag":"ambiguous-target-missing-task","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"}