{"record":{"id":"c4c09dd7dc80722a","repo":"hashicorp/nomad","slug":"port-q-cannot-be-mapped-to-negative-value-d","errorCode":null,"errorMessage":"Port %q cannot be mapped to negative value %d","messagePattern":"Port %q cannot be mapped to negative value (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7367,"sourceCode":"\t\t\t\t\tstaticPorts = make(map[int]string)\n\t\t\t\t}\n\t\t\t\t// static port\n\t\t\t\tif other, ok := staticPorts[port.Value]; ok {\n\t\t\t\t\tif !port.IgnoreCollision {\n\t\t\t\t\t\terr := fmt.Errorf(\"Static port %d already reserved by %s\", port.Value, other)\n\t\t\t\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t\t\t\t}\n\t\t\t\t} else if port.Value > math.MaxUint16 {\n\t\t\t\t\terr := fmt.Errorf(\"Port %s (%d) cannot be greater than %d\", port.Label, port.Value, math.MaxUint16)\n\t\t\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t\t\t} else {\n\t\t\t\t\tstaticPorts[port.Value] = fmt.Sprintf(\"taskgroup network:%s\", port.Label)\n\t\t\t\t\tstaticPortsIndex[hostNetwork] = staticPorts\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif port.To < -1 {\n\t\t\t\terr := fmt.Errorf(\"Port %q cannot be mapped to negative value %d\", port.Label, port.To)\n\t\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t\t} else if port.To > math.MaxUint16 {\n\t\t\t\terr := fmt.Errorf(\"Port %q cannot be mapped to a port (%d) greater than %d\", port.Label, port.To, math.MaxUint16)\n\t\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t\t}\n\n\t\t\tif port.IgnoreCollision && !(net.Mode == \"\" || net.Mode == \"host\") {\n\t\t\t\terr := fmt.Errorf(\"Port %q collision may not be ignored on non-host network mode %q\", port.Label, net.Mode)\n\t\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t\t}\n\t\t}\n\t\t// Validate the cniArgs in each network resource. Make sure there are no duplicate Args in\n\t\t// different network resources or invalid characters (;) in key or value ;)\n\t\tif net.CNI != nil {\n\t\t\tfor k, v := range net.CNI.Args {\n\t\t\t\tif cniArgKeys.Contains(k) {\n\t\t\t\t\terr := fmt.Errorf(\"duplicate CNI arg %q\", k)\n\t\t\t\t\tmErr.Errors = append(mErr.Errors, err)","sourceCodeStart":7349,"sourceCodeEnd":7385,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7349-L7385","documentation":"TaskGroup network validation: a port's 'to' mapping was less than -1. -1 is the sentinel meaning \"same as value\"; any value below that is not a valid destination port.","triggerScenarios":"Thrown at nomad/structs/structs.go:7367 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set to to a port in 0-65535, or -1 to map to the same port as value"],"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"}