{"record":{"id":"4488a3822b7a7e9e","repo":"hashicorp/nomad","slug":"invalid-port-q-not-a-valid-port-mapping-or-nume","errorCode":null,"errorMessage":"invalid port: %q: not a valid port mapping or numeric port","messagePattern":"invalid port: %q: not a valid port mapping or numeric port","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/serviceregistration/address.go","lineNumber":44,"sourceCode":") (string, int, error) {\n\tswitch addressMode {\n\tcase structs.AddressModeAuto:\n\t\tswitch {\n\t\tcase address != \"\":\n\t\t\t// No port no problem, just return the advertise address.\n\t\t\tif portLabel == \"\" {\n\t\t\t\treturn address, 0, nil\n\t\t\t}\n\t\t\t// A custom advertise address can be used with a port map; using the\n\t\t\t// Value and ignoring the IP. The routing from your custom address to\n\t\t\t// the group network address is DIY. (e.g. EC2 public address)\n\t\t\tif mapping, exists := ports.Get(portLabel); exists {\n\t\t\t\treturn address, mapping.Value, nil\n\t\t\t}\n\t\t\t// If not a port map we can interpolate a numeric port for you.\n\t\t\tport, err := strconv.Atoi(portLabel)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", 0, fmt.Errorf(\"invalid port: %q: not a valid port mapping or numeric port\", portLabel)\n\t\t\t}\n\t\t\treturn address, port, nil\n\t\tcase driverNet.Advertise():\n\t\t\treturn GetAddress(\"\", structs.AddressModeDriver, portLabel, networks, driverNet, ports, netStatus)\n\t\tdefault:\n\t\t\treturn GetAddress(\"\", structs.AddressModeHost, portLabel, networks, driverNet, ports, netStatus)\n\t\t}\n\tcase structs.AddressModeHost:\n\t\t// Cannot use address mode host with custom advertise address.\n\t\tif address != \"\" {\n\t\t\treturn \"\", 0, fmt.Errorf(\"cannot use custom advertise address with %q address mode\", structs.AddressModeHost)\n\t\t}\n\n\t\tif portLabel == \"\" {\n\t\t\tif len(networks) != 1 {\n\t\t\t\t// If no networks are specified return zero\n\t\t\t\t// values. Consul will advertise the host IP\n\t\t\t\t// with no port. This is the pre-0.7.1 behavior","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/serviceregistration/address.go#L26-L62","documentation":"In GetAddress under AddressModeAuto, the port label is neither a known port mapping (ports.Get) nor parseable as a numeric port, so no address/port pair can be produced for the service or check registration. Indicates a typo or missing port label in the job spec.","triggerScenarios":"Thrown at client/serviceregistration/address.go:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Define the port label in the group's network/port block","Use a numeric port literal instead of a label","Fix the label spelling in the service/check definition"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}