{"record":{"id":"fa5276de79a61b29","repo":"hashicorp/nomad","slug":"service-d-s-validation-failed-s","errorCode":null,"errorMessage":"Service[%d] %s validation failed: %s","messagePattern":"Service\\[(.+?)\\] (.+?) validation failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7531,"sourceCode":"\t\t\t// Track that we have seen this service provider\n\t\t\tproviderSet.Insert(service.Provider)\n\t\t}\n\t}\n\n\tfor i, service := range tg.Services {\n\n\t\t// Track that we have seen this service id\n\t\tid := unique{service.Name, \"group\", service.PortLabel}\n\t\tif !idSet.Insert(id) {\n\t\t\t// accumulate duplicates for a single error later on\n\t\t\tidDuplicateSet.Insert(id)\n\t\t}\n\n\t\t// Track that we have seen this service provider\n\t\tproviderSet.Insert(service.Provider)\n\n\t\tif err := service.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Service[%d] %s validation failed: %s\", i, service.Name, err)\n\t\t\tmErr.Errors = append(mErr.Errors, outer)\n\t\t\t// we break here to avoid the risk of crashing on null-pointer\n\t\t\t// access in a later step, accepting that we might miss out on\n\t\t\t// error messages to provide the user.\n\t\t\tcontinue\n\t\t}\n\t\tif service.AddressMode == AddressModeDriver {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"service %q cannot use address_mode=\\\"driver\\\", only services defined in a \\\"task\\\" block can use this mode\", service.Name))\n\t\t}\n\n\t\tfor _, check := range service.Checks {\n\t\t\tif check.TaskName != \"\" {\n\t\t\t\tif check.AddressMode == AddressModeDriver {\n\t\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Check %q invalid: cannot use address_mode=\\\"driver\\\", only checks defined in a \\\"task\\\" service block can use this mode\", service.Name))\n\t\t\t\t}\n\t\t\t\tif !taskSet.Contains(check.TaskName) {\n\t\t\t\t\tmErr.Errors = append(mErr.Errors,\n\t\t\t\t\t\tfmt.Errorf(\"Check %s invalid: refers to non-existent task %s\", check.Name, check.TaskName))","sourceCodeStart":7513,"sourceCodeEnd":7549,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7513-L7549","documentation":"A service failed its own Service.Validate(); Nomad wraps the underlying validation error as 'Service[%d] %s validation failed: %s' and appends it to the job's multi-error, then stops processing that service to avoid nil-pointer access downstream.","triggerScenarios":"Any invalid service definition (bad address_mode, empty port label when required, invalid check config, invalid provider, etc.) inside a group or task services block; the wrapped inner error names the real cause.","commonSituations":"Typo'd address_mode values; missing port_label for Consul services; check intervals/expose config errors; upgrading Nomad and newly-invalidated service fields.","solutions":["Read the '%s' suffix of the message for the underlying service.Validate error and fix that field.","Run nomad job validate to see the full wrapped error locally.","Compare the service stanza against the documented schema for your Nomad version."],"exampleFix":"// before\nservice { name=\"web\" address_mode=\"bogus\" }\n// after\nservice { name=\"web\" address_mode=\"auto\" port=\"http\" }","handlingStrategy":"try-catch","validationCode":"for i, svc := range services {\n  if err := svc.Validate(); err != nil {\n    return fmt.Errorf(\"Service[%d] %s: %w\", i, svc.Name, err)\n  }\n}","typeGuard":null,"tryCatchPattern":"mErr := job.Validate()\nif mErr != nil {\n  for _, e := range mErr.Errors {\n    var verr error\n    if errors.As(e, &verr) && strings.Contains(e.Error(), \"validation failed\") {\n      log.Printf(\"service error: %v\", verr)\n    }\n  }\n}","preventionTips":["Read the wrapped inner message — it names the exact bad field","Pin and read the service schema docs for your Nomad version","Run nomad job validate in CI before deploys"],"tags":["nomad","service","validation"],"backgroundTag":"service-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"}