{"record":{"id":"8e617250fd6256bf","repo":"hashicorp/nomad","slug":"no-port-of-label-q-defined","errorCode":null,"errorMessage":"No port of label %q defined","messagePattern":"No port of label %q defined","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/consul/connect.go","lineNumber":330,"sourceCode":"\t\treturn fmt.Errorf(\"Connect only supported with exactly 1 network (found %d)\", n)\n\t}\n\treturn nil\n}\n\n// connectPort returns the network and port for the Connect proxy sidecar\n// defined for this service. An error is returned if the network and port\n// cannot be determined.\nfunc connectPort(portLabel string, networks structs.Networks, ports structs.AllocatedPorts) (structs.AllocatedPortMapping, error) {\n\tif err := connectNetworkInvariants(networks); err != nil {\n\t\treturn structs.AllocatedPortMapping{}, err\n\t}\n\tmapping, ok := ports.Get(portLabel)\n\tif !ok {\n\t\tmapping = networks.Port(portLabel)\n\t\tif mapping.Value > 0 {\n\t\t\treturn mapping, nil\n\t\t}\n\t\treturn structs.AllocatedPortMapping{}, fmt.Errorf(\"No port of label %q defined\", portLabel)\n\t}\n\treturn mapping, nil\n}\n\n// connectExposePathPort returns the port for the exposed path for the exposed\n// proxy path.\nfunc connectExposePathPort(portLabel string, networks structs.Networks) (string, int, error) {\n\tif err := connectNetworkInvariants(networks); err != nil {\n\t\treturn \"\", 0, err\n\t}\n\n\tmapping := networks.Port(portLabel)\n\tif mapping.Value == 0 {\n\t\treturn \"\", 0, fmt.Errorf(\"No port of label %q defined\", portLabel)\n\t}\n\n\treturn mapping.HostIP, mapping.Value, nil\n}","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/consul/connect.go#L312-L348","documentation":"connectPort resolves the host port for a Connect sidecar from the service's PortLabel. When the label cannot be found in the allocation's ports (explicit Ports map or the task networks), and no positive port value exists, this error is returned.","triggerScenarios":"A connect-enabled service (or its sidecar_service) references a port_label that does not exist in the task's network ports, or the mapped port value is 0.","commonSituations":"Typos in port labels, port defined on a different task's network, port block omitted from the network stanza, or dynamic ports not allocated yet.","solutions":["Add the missing port label to the task's network block so it matches the service's port_label.","Fix the port_label spelling to match an existing port definition.","Run nomad job validate to catch label mismatches before submission."],"exampleFix":"// before\nconnect { sidecar_service {} } // service port_label = \"http\"\n// but network has no http port\n// after\nnetwork {\n  mode = \"bridge\"\n  port \"http\" {}\n}","handlingStrategy":"validation","validationCode":"for _, svc := range task.Services {\n  if _, ok := ports[svc.PortLabel]; !ok {\n    return fmt.Errorf(\"service %s: port label %q undefined\", svc.Name, svc.PortLabel)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cross-check every service port_label against the network block.","Use nomad job validate as a pre-submit gate.","Keep port label names consistent between network and service stanzas."],"tags":["consul","connect","port-label","nomad"],"backgroundTag":"missing-port-label","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"}