{"record":{"id":"a79026da51b769cd","repo":"hashicorp/nomad","slug":"invalid-port-q-port-must-be-0","errorCode":null,"errorMessage":"invalid port: %q: port must be >0","messagePattern":"invalid port: %q: port must be >0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/serviceregistration/address.go","lineNumber":88,"sourceCode":"\t\t// Try finding port in the AllocatedPorts struct first\n\t\t// Check in Networks struct for backwards compatibility if not found\n\t\tmapping, ok := ports.Get(portLabel)\n\t\tif !ok {\n\t\t\tmapping = networks.Port(portLabel)\n\t\t\tif mapping.Value > 0 {\n\t\t\t\treturn mapping.HostIP, mapping.Value, nil\n\t\t\t}\n\n\t\t\t// If port isn't a label, try to parse it as a literal port number\n\t\t\tport, err := strconv.Atoi(portLabel)\n\t\t\tif err != nil {\n\t\t\t\t// Don't include Atoi error message as user likely\n\t\t\t\t// never intended it to be a numeric and it creates a\n\t\t\t\t// confusing error message\n\t\t\t\treturn \"\", 0, fmt.Errorf(\"invalid port %q: port label not found\", portLabel)\n\t\t\t}\n\t\t\tif port <= 0 {\n\t\t\t\treturn \"\", 0, fmt.Errorf(\"invalid port: %q: port must be >0\", portLabel)\n\t\t\t}\n\n\t\t\t// A number was given which will use the Consul agent's address and the given port\n\t\t\t// Returning a blank string as an address will use the Consul agent's address\n\t\t\treturn \"\", port, nil\n\t\t}\n\t\treturn mapping.HostIP, mapping.Value, nil\n\n\tcase structs.AddressModeDriver:\n\t\t// Cannot use address mode driver 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.AddressModeDriver)\n\t\t}\n\n\t\t// Require a driver network if driver address mode is used\n\t\tif driverNet == nil {\n\t\t\treturn \"\", 0, fmt.Errorf(`cannot use address_mode=\"driver\": no driver network exists`)\n\t\t}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/serviceregistration/address.go#L70-L106","documentation":"Returned by GetAddress when a port label resolves to no allocated or network port and cannot be parsed as a positive integer literal. The label is neither known nor numeric, so no host port can be determined for service registration.","triggerScenarios":"Thrown at client/serviceregistration/address.go:88 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a port number > 0 in the service/check port field","Fix interpolation producing 0 (e.g. missing NOMAD_PORT_ env)"],"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-08T10:18:20.063Z"}