{"record":{"id":"814f9f2040542858","repo":"hashicorp/nomad","slug":"invalid-address-mode-q","errorCode":null,"errorMessage":"invalid address mode %q","messagePattern":"invalid address mode %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/serviceregistration/address.go","lineNumber":176,"sourceCode":"\t\t\t}\n\n\t\t\treturn getAddressPort(addressMode, netStatus, port.Value)\n\t\t}\n\n\t\t// Check if port is a literal number\n\t\tport, err := strconv.Atoi(portLabel)\n\t\tif err != nil {\n\t\t\t// User likely specified wrong port label here\n\t\t\treturn \"\", 0, fmt.Errorf(\"invalid port %q: port label not found or is not numeric\", portLabel)\n\t\t}\n\t\tif port <= 0 {\n\t\t\treturn \"\", 0, fmt.Errorf(\"invalid port: %q: port must be >0\", portLabel)\n\t\t}\n\n\t\treturn getAddressPort(addressMode, netStatus, port)\n\tdefault:\n\t\t// Shouldn't happen due to validation, but enforce invariants\n\t\treturn \"\", 0, fmt.Errorf(\"invalid address mode %q\", addressMode)\n\t}\n}\n\n// getAddressPort is a helper function to return the IPv6 or IPv4 address based on the addressMode\nfunc getAddressPort(addressMode string, netStatus *structs.AllocNetworkStatus, port int) (string, int, error) {\n\tif addressMode == structs.AddressModeAllocIPv6 {\n\t\treturn netStatus.AddressIPv6, port, nil\n\t}\n\n\treturn netStatus.Address, port, nil\n}\n","sourceCodeStart":158,"sourceCodeEnd":188,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/serviceregistration/address.go#L158-L188","documentation":"GetAddress switches on the service's address_mode (host, driver, alloc, alloc_ipv6). The default branch enforces invariants: job validation should have rejected unknown modes earlier, so hitting this error at runtime indicates an unrecognized address mode string reached the resolver anyway.","triggerScenarios":"An address mode value other than \"host\", \"driver\", \"alloc\", or \"alloc_ipv6\" is passed to GetAddress — normally only possible if validation was bypassed, an API client submitted an unvalidated job, or a new/unknown mode comes from an older/newer binary mismatch.","commonSituations":"Submitting jobs via the raw API skipping server-side validation; typo'd address_mode in generated/templated job specs; mixing Nomad versions where an address_mode value is not recognized by the client binary.","solutions":["Correct address_mode in the job spec to one of: host, driver, alloc, alloc_ipv6","Re-run nomad job validate / submit through the API so validation rejects bad modes upfront","Ensure client and server Nomad versions are consistent (mode support differs across versions)"],"exampleFix":"// before\nservice {\n  name = \"web\"\n  address_mode = \"allocation\"\n}\n// after\nservice {\n  name = \"web\"\n  address_mode = \"alloc\"\n}","handlingStrategy":"validation","validationCode":"var validAddressModes = map[string]bool{\"host\": true, \"driver\": true, \"alloc\": true, \"alloc_ipv6\": true}\nif !validAddressModes[service.AddressMode] {\n    return fmt.Errorf(\"service %q: invalid address_mode %q\", service.Name, service.AddressMode)\n}","typeGuard":"func isValidAddressMode(m string) bool {\n    switch m {\n    case \"host\", \"driver\", \"alloc\", \"alloc_ipv6\":\n        return true\n    }\n    return false\n}","tryCatchPattern":"ip, port, err := GetAddress(addr, mode, portLabel, networks, dn, ports, netStatus)\nif err != nil && strings.Contains(err.Error(), \"invalid address mode\") {\n    logger.Error(\"unknown address mode reached resolver; fix job spec\", \"mode\", mode)\n    return err\n}","preventionTips":["Submit jobs through the API/nomad CLI so server-side validation rejects bad modes","Keep client and server Nomad versions aligned","Avoid hand-crafting job JSON that bypasses HCL validation"],"tags":["nomad","service-registration","invalid-enum","invariant"],"backgroundTag":"invalid-enum-value","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"}