{"record":{"id":"61cf8689ef9011a3","repo":"hashicorp/nomad","slug":"must-provide-task-name","errorCode":null,"errorMessage":"must provide task name","messagePattern":"must provide task name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"client/fs_endpoint.go","lineNumber":35,"sourceCode":"\t\"strings\"\n\t\"syscall\"\n\t\"time\"\n\n\tmetrics \"github.com/hashicorp/go-metrics/compat\"\n\t\"github.com/hashicorp/go-msgpack/v2/codec\"\n\t\"github.com/hpcloud/tail/watch\"\n\n\t\"github.com/hashicorp/nomad/acl\"\n\t\"github.com/hashicorp/nomad/client/allocdir\"\n\tsframer \"github.com/hashicorp/nomad/client/lib/streamframer\"\n\tcstructs \"github.com/hashicorp/nomad/client/structs\"\n\t\"github.com/hashicorp/nomad/nomad/structs\"\n)\n\nvar (\n\tallocIDNotPresentErr = fmt.Errorf(\"must provide a valid alloc id\")\n\tpathNotPresentErr    = fmt.Errorf(\"must provide a file path\")\n\ttaskNotPresentErr    = fmt.Errorf(\"must provide task name\")\n\tlogTypeNotPresentErr = fmt.Errorf(\"must provide log type (stdout/stderr)\")\n\tinvalidOrigin        = fmt.Errorf(\"origin must be start or end\")\n)\n\nconst (\n\t// streamFramesBuffer is the number of stream frames that will be buffered\n\t// before back pressure is applied on the stream framer.\n\tstreamFramesBuffer = 32\n\n\t// streamFrameSize is the maximum number of bytes to send in a single frame\n\tstreamFrameSize = 64 * 1024\n\n\t// streamHeartbeatRate is the rate at which a heartbeat will occur to detect\n\t// a closed connection without sending any additional data\n\tstreamHeartbeatRate = 1 * time.Second\n\n\t// streamBatchWindow is the window in which file content is batched before\n\t// being flushed if the frame size has not been hit.","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/fs_endpoint.go#L17-L53","documentation":"taskNotPresentErr is a sentinel error for requests that omit the Task name. Log retrieval and exec both operate on a specific task within the allocation, so Task must be non-empty. Returned with HTTP 400 from both client/fs_endpoint.go and client/alloc_endpoint.go paths.","triggerScenarios":"Calling logs, Logs, or execImpl with req.Task == \"\" — e.g. /v1/client/fs/logs/<alloc> without ?task= or an exec request built without the task field.","commonSituations":"Tooling that assumes single-task allocations and skips the task parameter; group jobs with multiple tasks where the UI variable for task is unset; hand-rolled HTTP calls missing the query param.","solutions":["Add the task query parameter (or req.Task field) naming a task in the allocation","Look up valid task names via nomad alloc status <alloc_id> and pass one explicitly","In code, validate req.Task != \"\" before invoking the endpoint"],"exampleFix":"// before\nGET /v1/client/fs/logs/<alloc_id>?type=stdout\n// after\nGET /v1/client/fs/logs/<alloc_id>?task=web&type=stdout","handlingStrategy":"validation","validationCode":"tasks, _, err := client.Allocations().Tasks(alloc, nil)\nif err != nil {\n    return err\n}\nif task == \"\" {\n    if len(tasks) == 1 {\n        task = tasks[0].Name\n    } else {\n        return fmt.Errorf(\"task is required; allocation has tasks: %v\", taskNames(tasks))\n    }\n}","typeGuard":"func hasTask(req *cstructs.FsLogsRequest) bool {\n    return req != nil && req.Task != \"\"\n}","tryCatchPattern":"logs, err := client.AllocFS().Logs(alloc, \"web\", \"\", false, \"stdout\", \"start\", 0, nil, nil)\nif err != nil && strings.Contains(err.Error(), \"must provide task name\") {\n    return fmt.Errorf(\"specify -task; alloc %s contains multiple tasks\", alloc.ID)\n}","preventionTips":["For multi-task groups always require an explicit task selector in your tooling","Auto-fill the task only when the allocation provably has exactly one task","Validate Task != \"\" in wrappers around AllocFS/Alloc/exec APIs"],"tags":["api","validation","logs","exec"],"backgroundTag":"missing-required-argument","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"}