{"record":{"id":"b08a6101f375fb9e","repo":"hashicorp/nomad","slug":"task-group-count-can-t-be-negative","errorCode":null,"errorMessage":"Task group count can't be negative","messagePattern":"Task group count can't be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7134,"sourceCode":"\t\t\t\tservices = append(services, service)\n\t\t\t}\n\t\t}\n\t}\n\treturn services\n}\n\n// Validate is used to check a task group for reasonable configuration\nfunc (tg *TaskGroup) Validate(j *Job) error {\n\tvar mErr *multierror.Error\n\n\tif tg.Name == \"\" {\n\t\tmErr = multierror.Append(mErr, errors.New(\"Missing task group name\"))\n\t} else if strings.Contains(tg.Name, \"\\000\") {\n\t\tmErr = multierror.Append(mErr, errors.New(\"Task group name contains null character\"))\n\t}\n\n\tif tg.Count < 0 {\n\t\tmErr = multierror.Append(mErr, errors.New(\"Task group count can't be negative\"))\n\t}\n\n\tif len(tg.Tasks) == 0 {\n\t\t// could be a lone consul gateway inserted by the connect mutator\n\t\tmErr = multierror.Append(mErr, errors.New(\"Missing tasks for task group\"))\n\t}\n\n\tif tg.Disconnect != nil {\n\t\tif err := tg.Disconnect.Validate(j); err != nil {\n\t\t\tmErr = multierror.Append(mErr, err)\n\t\t}\n\t}\n\n\tif tg.MaxRunDuration != nil {\n\t\tif *tg.MaxRunDuration <= 0 {\n\t\t\tmErr = multierror.Append(mErr, errors.New(\"MaxRunDuration must be greater than zero\"))\n\t\t}\n","sourceCodeStart":7116,"sourceCodeEnd":7152,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7116-L7152","documentation":"A task group must declare at least one task; TaskGroup.Validate appends this error when len(tg.Tasks) == 0. The only tolerated case (lone Consul gateways injected by the connect mutator) is handled elsewhere, so an empty user-supplied group always fails.","triggerScenarios":"Submitting a job where a group stanza contains no task blocks; building TaskGroup structs in code without appending any Task.","commonSituations":"HCL group block whose task stanza was commented out or mis-indented; JSON jobs generated dynamically where the task list ended up empty; refactor that moved tasks to another group.","solutions":["Add at least one task block inside each group.","Fix indentation in HCL so the task stanza is inside the group.","When generating jobs programmatically, assert len(tasks) > 0 before submission."],"exampleFix":"// before\ngroup \"web\" {\n  # task \"server\" { ... } accidentally commented\n}\n// after\ngroup \"web\" {\n  task \"server\" {\n    driver = \"docker\"\n    config { image = \"nginx\" }\n  }\n}","handlingStrategy":"validation","validationCode":"if len(tg.Tasks) == 0 {\n    return errors.New(\"task group requires at least one task\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure task stanzas are correctly indented inside their group","Check that code generation actually appends tasks","Run nomad job validate before every submit"],"tags":["nomad","job-validation","missing-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"}