{"record":{"id":"87ef418f49b0de67","repo":"docker/cli","slug":"invalid-field-s-87ef41","errorCode":null,"errorMessage":"invalid field: %s","messagePattern":"invalid field: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/swarmopts/port.go","lineNumber":56,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tif longSyntax {\n\t\tcsvReader := csv.NewReader(strings.NewReader(value))\n\t\tfields, err := csvReader.Read()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tpConfig := swarm.PortConfig{\n\t\t\tProtocol:    network.TCP,\n\t\t\tPublishMode: swarm.PortConfigPublishModeIngress,\n\t\t}\n\t\tfor _, field := range fields {\n\t\t\t// TODO(thaJeztah): these options should not be case-insensitive.\n\t\t\tkey, val, ok := strings.Cut(strings.ToLower(field), \"=\")\n\t\t\tif !ok || key == \"\" {\n\t\t\t\treturn fmt.Errorf(\"invalid field: %s\", field)\n\t\t\t}\n\t\t\tswitch key {\n\t\t\tcase portOptProtocol:\n\t\t\t\tswitch proto := network.IPProtocol(val); proto {\n\t\t\t\tcase network.TCP, network.UDP, network.SCTP:\n\t\t\t\t\tpConfig.Protocol = proto\n\t\t\t\tdefault:\n\t\t\t\t\treturn fmt.Errorf(\"invalid protocol value '%s'\", val)\n\t\t\t\t}\n\t\t\tcase portOptMode:\n\t\t\t\tswitch swarm.PortConfigPublishMode(val) {\n\t\t\t\tcase swarm.PortConfigPublishModeIngress, swarm.PortConfigPublishModeHost:\n\t\t\t\t\tpConfig.PublishMode = swarm.PortConfigPublishMode(val)\n\t\t\t\tdefault:\n\t\t\t\t\treturn fmt.Errorf(\"invalid publish mode value (%s): must be either '%s' or '%s'\", val, swarm.PortConfigPublishModeIngress, swarm.PortConfigPublishModeHost)\n\t\t\t\t}\n\t\t\tcase portOptTargetPort:\n\t\t\t\ttPort, err := strconv.ParseUint(val, 10, 16)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/swarmopts/port.go#L38-L74","documentation":"Thrown by PortOpt.Set (port.go:56) when a field in the long-syntax --publish value lacks '=' or has an empty key. Long syntax looks like `published=8080,target=80,protocol=tcp,mode=ingress`; any field not matching key=value (or with an empty key after lowercasing) is rejected.","triggerScenarios":"Passing `--publish published=8080,target` (no value for target), `--publish 8080:80,mode=ingress` (mixing short and long), or a field like `=tcp`. strings.Cut at line 54 yields ok=false or empty key.","commonSituations":"Mixing the short `IP:PUBLIC:PRIVATE/proto` form with key=value long form, truncating a field, copy-paste errors, or a missing '=' after a key.","solutions":["Use consistent long syntax: `--publish published=8080,target=80,protocol=tcp,mode=ingress`.","Or use short syntax throughout: `--publish 8080:80`.","Ensure every field has the form key=value with a non-empty key.","Avoid stray commas that create empty fields."],"exampleFix":"// before\n--publish published=8080,target\n// after\n--publish published=8080,target=80","handlingStrategy":"validation","validationCode":"// Check each long-syntax --publish field is key=value with a non-empty key.\nfor _, f := range strings.Split(pubVal, \",\") {\n    k, _, ok := strings.Cut(strings.ToLower(strings.TrimSpace(f)), \"=\")\n    if !ok || k == \"\" { return fmt.Errorf(\"publish field %q must be key=value\", f) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't mix short (a:b) and long (k=v) syntax in one --publish.","Always provide a value after '=' for each key.","Watch for trailing commas creating empty fields.","Prefer one syntax consistently per flag."],"tags":["docker","swarm","port","validation","cli","networking"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}