{"record":{"id":"19e744b3c7573d6b","repo":"hashicorp/nomad","slug":"task-name-must-be-set","errorCode":null,"errorMessage":"task name must be set","messagePattern":"task name must be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/node.go","lineNumber":433,"sourceCode":"\tNodeID string\n\n\t// AllocID is the allocation being targeted by this request.\n\tAllocID string\n\n\t// TaskName is the name of the task being targeted by this request.\n\tTaskName string\n\n\t// State is the state to apply to the task being targeted by this request.\n\tScheduleState TaskScheduleState\n}\n\nfunc (r *ScheduleStateApplyRequest) Validate() error {\n\tif r.AllocID == \"\" {\n\t\treturn errors.New(\"alloc id must be set\")\n\t}\n\n\tif r.TaskName == \"\" {\n\t\treturn errors.New(\"task name must be set\")\n\t}\n\n\tswitch r.ScheduleState {\n\tcase TaskScheduleStateRun:\n\tcase TaskScheduleStateForceRun:\n\tcase TaskScheduleStateSchedPause:\n\tcase TaskScheduleStateForcePause:\n\tdefault:\n\t\treturn errors.New(\"not a valid task schedule state\")\n\t}\n\n\treturn nil\n}\n\n// ScheduleStateReadRequest is used to read the current pause state of a specific\n// task running on a client.\ntype ScheduleStateReadRequest struct {\n\tQueryOptions // Client RPCs must use QueryOptions","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/node.go#L415-L451","documentation":"ScheduleStateApplyRequest.Validate requires TaskName to identify which task inside the allocation the schedule state (run/force_run/sched_pause/force_pause) applies to. An empty TaskName fails with 'task name must be set'.","triggerScenarios":"Submitting a ScheduleStateApplyRequest with r.TaskName == \"\" after AllocID passed validation; commonly when callers target 'the only task' implicitly.","commonSituations":"Automation assuming a single-task allocation and omitting task name; HCL/JSON job files where task names differ from what tooling sends; renamed tasks after a template change.","solutions":["Set TaskName to the exact task name from the job specification","Look up the task name from the allocation's TaskStates map or job spec rather than hardcoding","Check for task renames between job versions that invalidate hardcoded names","Validate client-side (non-empty TaskName) before hitting the API"],"exampleFix":"// before\nreq := &structs.ScheduleStateApplyRequest{\n  AllocID: allocID,\n  ScheduleState: structs.TaskScheduleStateForcePause,\n}\n\n// after\nreq := &structs.ScheduleStateApplyRequest{\n  AllocID: allocID,\n  TaskName: \"redis\",\n  ScheduleState: structs.TaskScheduleStateForcePause,\n}","handlingStrategy":"validation","validationCode":"if req.TaskName == \"\" {\n\treturn errors.New(\"task name required before applying schedule state\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Take task names from allocation TaskStates, not hardcoded values","Track task renames across job versions","Make task name a required CLI/automation parameter"],"tags":["nomad","task-scheduling","validation","required-field"],"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"}