{"record":{"id":"69fa934618a19b23","repo":"hashicorp/nomad","slug":"task-d-missing-name","errorCode":null,"errorMessage":"Task %d missing name","messagePattern":"Task (.+?) missing name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7254,"sourceCode":"\tcase JobTypeService:\n\t\tif tg.Migrate != nil {\n\t\t\tif err := tg.Migrate.Validate(); err != nil {\n\t\t\t\tmErr = multierror.Append(mErr, err)\n\t\t\t}\n\t\t}\n\tdefault:\n\t\tif tg.Migrate != nil {\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"Job type %q does not allow migrate block\", j.Type))\n\t\t}\n\t}\n\n\t// Check that there is only one leader task if any\n\ttasks := make(map[string]int)\n\tleaderTasks := 0\n\tmainTasks := 0\n\tfor idx, task := range tg.Tasks {\n\t\tif task.Name == \"\" {\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"Task %d missing name\", idx+1))\n\t\t} else if existing, ok := tasks[task.Name]; ok {\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"Task %d redefines '%s' from task %d\", idx+1, task.Name, existing+1))\n\t\t} else {\n\t\t\ttasks[task.Name] = idx\n\t\t}\n\n\t\tif task.Leader {\n\t\t\tleaderTasks++\n\t\t}\n\n\t\tif task.IsMain() {\n\t\t\tmainTasks++\n\t\t}\n\t}\n\n\tif leaderTasks > 1 {\n\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"Only one task may be marked as leader\"))\n\t}","sourceCodeStart":7236,"sourceCodeEnd":7272,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7236-L7272","documentation":"During TaskGroup.Validate, every task in the group must have a non-empty `name`. When a task is found with an empty name, Nomad appends this error (1-indexed by position in the group) to the job's multierror, since unnamed tasks cannot be scheduled, referenced by services, or reported on.","triggerScenarios":"Submitting a job where a `task` block inside a group has no `name` field (empty string), typically from programmatic job construction or template substitution that dropped the name.","commonSituations":"Generating job specs in code/Golang SDK with an unset Task.Name; templating (e.g. `${task_name}` rendered empty); hand-edited HCL where the name line was deleted.","solutions":["Add a unique, non-empty `name` to each task block in the group.","If generating the job via the SDK/API, set the Name field explicitly before submission."],"exampleFix":"// before\ntask \"\" {\n  driver = \"docker\"\n}\n// after\ntask \"myapp\" {\n  driver = \"docker\"\n}","handlingStrategy":"validation","validationCode":"// Go: check task names before submission\nfor _, tg := range job.TaskGroups {\n  for i, t := range tg.Tasks {\n    if t.Name == \"\" {\n      return fmt.Errorf(\"group %q task %d: name is required\", tg.Name, i+1)\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set task Name explicitly in SDK-generated jobs.","Guard templating variables that supply task names against empty values.","Run `nomad job validate` on generated specs before submit."],"tags":["nomad","job-validation","task-definition"],"backgroundTag":"nomad-job-validation-failed","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"}