{"record":{"id":"9f2709efc5ca0cbd","repo":"hashicorp/nomad","slug":"unknown-task-name-q-9f2709","errorCode":null,"errorMessage":"unknown task name %q","messagePattern":"unknown task name %q","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"client/fs_endpoint.go","lineNumber":437,"sourceCode":"\t\treturn\n\t}\n\n\tallocState, err := f.c.GetAllocState(req.AllocID)\n\tif err != nil {\n\t\tcode := new(int64(http.StatusInternalServerError))\n\t\tif structs.IsErrUnknownAllocation(err) {\n\t\t\tcode = new(int64(http.StatusNotFound))\n\t\t}\n\n\t\thandleStreamResultError(err, code, encoder)\n\t\treturn\n\t}\n\n\t// Check that the task is there\n\ttaskState := allocState.TaskStates[req.Task]\n\tif taskState == nil {\n\t\thandleStreamResultError(\n\t\t\tfmt.Errorf(\"unknown task name %q\", req.Task),\n\t\t\tnew(int64(http.StatusBadRequest)),\n\t\t\tencoder)\n\t\treturn\n\t}\n\n\tif taskState.StartedAt.IsZero() {\n\t\thandleStreamResultError(\n\t\t\tfmt.Errorf(\"task %q not started yet. No logs available\", req.Task),\n\t\t\tnew(int64(http.StatusNotFound)),\n\t\t\tencoder)\n\t\treturn\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\tframes := make(chan *sframer.StreamFrame, streamFramesBuffer)\n\terrCh := make(chan error)","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/fs_endpoint.go#L419-L455","documentation":"The logs endpoint validates the requested task name against the allocation's TaskStates map. If no task state exists for the given name, the endpoint returns HTTP 400 with this message. This is a request-side naming error, not an infrastructure failure.","triggerScenarios":"Calling GET /v1/client/fs/logs (or client.Allocs().Logs) with a task parameter that does not match any task in the allocation's task group — typo, wrong case, or a task name from a different group/job version.","commonSituations":"Copy-pasting a task name across job files; renaming a task in the job spec while log tooling still uses the old name; passing the group name instead of the task name; job versions where the task list changed.","solutions":["Use the exact task name from the job spec (check alloc.TaskNames / alloc.TaskStates via the API).","Fetch the allocation with Allocations().Info and pick a task name from TaskStates before calling the logs API.","Fix typos and case mismatches in the task parameter; names are case-sensitive."],"exampleFix":"// before\nlogs, err := client.Allocs().Logs(alloc, false, \"Web\", \"stdout\", nil, nil)\n// after\nnames, _, err := client.Allocations().TaskNames(alloc.ID, nil)\nif err != nil || len(names) == 0 {\n    return err\n}\nlogs, err = client.Allocs().Logs(alloc, false, names[0], \"stdout\", nil, nil)","handlingStrategy":"validation","validationCode":"a, _, err := client.Allocations().Info(allocID, nil)\nif err != nil {\n    return err\n}\nif _, ok := a.TaskStates[taskName]; !ok {\n    return fmt.Errorf(\"task %q not in alloc; valid: %v\", taskName, keys(a.TaskStates))\n}","typeGuard":"func taskExists(a *api.Allocation, task string) bool {\n    return a != nil && a.TaskStates != nil && a.TaskStates[task] != nil\n}","tryCatchPattern":"if err := fetchLogs(task); err != nil {\n    if strings.Contains(err.Error(), \"unknown task name\") {\n        return fmt.Errorf(\"fix task name; see alloc.TaskStates\")\n    }\n    return err\n}","preventionTips":["Derive task names from alloc.TaskStates, not hardcoded strings.","Remember task names are case-sensitive and distinct from group names.","Update tooling when renaming tasks in the job spec."],"tags":["nomad","client","logs","bad-request","task-name"],"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"}