{"record":{"id":"959077223591e531","repo":"lima-vm/lima","slug":"field-s-hostportrange-1-must-be-greater-than-o","errorCode":null,"errorMessage":"field `%s.hostPortRange[1]` must be greater than or equal to field `%s.hostPortRange[0]`","messagePattern":"field `(.+?)\\.hostPortRange\\[1\\]` must be greater than or equal to field `(.+?)\\.hostPortRange\\[0\\]`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/limayaml/validate.go","lineNumber":350,"sourceCode":"\t\t\tif err := validatePort(field+\".hostPort\", rule.HostPort); err != nil {\n\t\t\t\terrs = errors.Join(errs, err)\n\t\t\t}\n\t\t}\n\t\tfor j := range 2 {\n\t\t\tif err := validatePort(fmt.Sprintf(\"%s.guestPortRange[%d]\", field, j), rule.GuestPortRange[j]); err != nil {\n\t\t\t\terrs = errors.Join(errs, err)\n\t\t\t}\n\t\t\tif rule.HostSocket == \"\" {\n\t\t\t\tif err := validatePort(fmt.Sprintf(\"%s.hostPortRange[%d]\", field, j), rule.HostPortRange[j]); err != nil {\n\t\t\t\t\terrs = errors.Join(errs, err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif rule.GuestPortRange[0] > rule.GuestPortRange[1] {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.guestPortRange[1]` must be greater than or equal to field `%s.guestPortRange[0]`\", field, field))\n\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] {","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/limayaml/validate.go#L332-L368","documentation":"The host port range is inverted: hostPortRange[1] (end) is smaller than hostPortRange[0] (start), so no valid port interval can be forwarded.","triggerScenarios":"Validate on a LimaYAML where portForwards[i].HostPortRange[0] > HostPortRange[1] and HostSocket == \"\" — e.g. hostPortRange: [9000, 8080].","commonSituations":"Typo in a manually written range; assuming [end, start] ordering; template generation code that computes hi/lo in the wrong order.","solutions":["Swap the values so hostPortRange[0] <= hostPortRange[1]","Use a single-element range [n, n] if only one port is needed"],"exampleFix":"// before\nportForwards:\n  - guestPortRange: [8080, 8081]\n    hostPortRange: [8081, 8080]\n// after\nportForwards:\n  - guestPortRange: [8080, 8081]\n    hostPortRange: [8080, 8081]","handlingStrategy":"validation","validationCode":"for i, rule := range y.PortForwards {\n  if rule.HostSocket == \"\" && rule.HostPortRange[0] > rule.HostPortRange[1] {\n    return fmt.Errorf(\"portForwards[%d]: hostPortRange is inverted\", i)\n  }\n}","typeGuard":"func hostRangeOrdered(r [2]int) bool { return r[0] <= r[1] }","tryCatchPattern":"if err := limayaml.Validate(y, false); err != nil {\n  if strings.Contains(err.Error(), \"hostPortRange[1]` must be greater\") {\n    // swap hostPortRange elements\n  }\n}","preventionTips":["Write ranges as [low, high] consistently for guest and host","Compute ranges with min/max helpers in generators","Validate configs before `limactl start`"],"tags":["lima","port-forwarding","config-validation"],"backgroundTag":"port-forward-range-inverted","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}