{"record":{"id":"a31d8b27ad849df0","repo":"lima-vm/lima","slug":"field-s-hostsocket-can-only-be-mapped-from-a-si","errorCode":null,"errorMessage":"field `%s.hostSocket` can only be mapped from a single port or socket. not a range","messagePattern":"field `(.+?)\\.hostSocket` can only be mapped from a single port or socket\\. not a range","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/limayaml/validate.go","lineNumber":366,"sourceCode":"\t\t}\n\t\tif rule.HostPortRange[0] > rule.HostPortRange[1] {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.hostPortRange[1]` must be greater than or equal to field `%s.hostPortRange[0]`\", field, field))\n\t\t}\n\t\tif rule.GuestSocket != \"\" {\n\t\t\tif !path.IsAbs(rule.GuestSocket) {\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.guestSocket` must be an absolute path, but is %#q\", field, rule.GuestSocket))\n\t\t\t}\n\t\t\tif rule.HostSocket == \"\" && rule.HostPortRange[1]-rule.HostPortRange[0] > 0 {\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.guestSocket` can only be mapped to a single port or socket. not a range\", field))\n\t\t\t}\n\t\t}\n\t\tif rule.HostSocket != \"\" {\n\t\t\tif !filepath.IsAbs(rule.HostSocket) {\n\t\t\t\t// should be unreachable because FillDefault() will prepend the instance directory to relative names\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.hostSocket` must be an absolute path, but is %#q\", field, rule.HostSocket))\n\t\t\t}\n\t\t\tif rule.GuestSocket == \"\" && rule.GuestPortRange[1]-rule.GuestPortRange[0] > 0 {\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.hostSocket` can only be mapped from a single port or socket. not a range\", field))\n\t\t\t}\n\t\t} else if rule.GuestPortRange[1]-rule.GuestPortRange[0] != rule.HostPortRange[1]-rule.HostPortRange[0] {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.hostPortRange` must specify the same number of ports as field `%s.guestPortRange`\", field, field))\n\t\t}\n\n\t\tif len(rule.HostSocket) >= osutil.UnixPathMax {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.hostSocket` must be less than UNIX_PATH_MAX=%d characters, but is %d\",\n\t\t\t\tfield, osutil.UnixPathMax, len(rule.HostSocket)))\n\t\t}\n\t\tswitch rule.Proto {\n\t\tcase limatype.ProtoTCP, limatype.ProtoUDP, limatype.ProtoAny:\n\t\tdefault:\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.proto` must be %#q, %#q, or %#q\", field, limatype.ProtoTCP, limatype.ProtoUDP, limatype.ProtoAny))\n\t\t}\n\t\tif rule.Reverse && rule.GuestSocket == \"\" {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.reverse` must be %t\", field, false))\n\t\t}\n\t\tif rule.Reverse && rule.HostSocket == \"\" {","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/limayaml/validate.go#L348-L384","documentation":"A hostSocket endpoint can accept traffic from only a single guest endpoint. If the guest side is a port range spanning more than one port (guestSocket empty and guestPortRange width > 0), the mapping is ambiguous and rejected.","triggerScenarios":"Validate on a LimaYAML where portForwards[i].HostSocket != \"\", GuestSocket == \"\", and GuestPortRange[1]-GuestPortRange[0] > 0 (e.g. guestPortRange: [3000, 3010] with hostSocket set).","commonSituations":"Switching an existing multi-port rule to a host socket without shrinking guestPortRange; copying the hostSocket field into a range-based rule.","solutions":["Collapse guestPortRange to a single port, e.g. [3000, 3000]","Or replace hostSocket with a hostPortRange of the same width","Create one rule per guest port, each with its own hostSocket"],"exampleFix":"// before\nportForwards:\n  - guestPortRange: [3000, 3010]\n    hostSocket: /tmp/app.sock\n// after\nportForwards:\n  - guestPortRange: [3000, 3000]\n    hostSocket: /tmp/app.sock","handlingStrategy":"validation","validationCode":"for i, rule := range y.PortForwards {\n  if rule.HostSocket != \"\" && rule.GuestSocket == \"\" && rule.GuestPortRange[1]-rule.GuestPortRange[0] > 0 {\n    return fmt.Errorf(\"portForwards[%d]: hostSocket needs a single guest port\", i)\n  }\n}","typeGuard":"func singleGuestPort(rule limatype.PortForward) bool { return rule.GuestSocket != \"\" || rule.GuestPortRange[1]-rule.GuestPortRange[0] == 0 }","tryCatchPattern":"if err := limayaml.Validate(y, false); err != nil {\n  if strings.Contains(err.Error(), \"hostSocket` can only be mapped from a single port\") {\n    // narrow guestPortRange to a single port\n  }\n}","preventionTips":["When adding hostSocket, collapse guestPortRange to [n, n]","Map each guest port with its own rule if multiple ports are needed","Prefer hostPortRange over hostSocket for multi-port rules"],"tags":["lima","port-forwarding","unix-socket","config-validation"],"backgroundTag":"socket-port-range-mismatch","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}