{"record":{"id":"0b4c50ee1d2d8326","repo":"lima-vm/lima","slug":"field-s-hostport-must-match-field-s-hostportr","errorCode":null,"errorMessage":"field `%s.hostPort` must match field `%s.hostPortRange[0]`","messagePattern":"field `(.+?)\\.hostPort` must match field `(.+?)\\.hostPortRange\\[0\\]`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/limayaml/validate.go","lineNumber":329,"sourceCode":"\t\t}\n\t\tif rule.GuestPort != 0 {\n\t\t\tif rule.GuestSocket != \"\" {\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.guestPort` must be 0 when field `%s.guestSocket` is set\", field, field))\n\t\t\t}\n\t\t\tif rule.GuestPort != rule.GuestPortRange[0] {\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.guestPort` must match field `%s.guestPortRange[0]`\", field, field))\n\t\t\t}\n\t\t\t// redundant validation to make sure the error contains the correct field name\n\t\t\tif err := validatePort(field+\".guestPort\", rule.GuestPort); err != nil {\n\t\t\t\terrs = errors.Join(errs, err)\n\t\t\t}\n\t\t}\n\t\tif rule.HostPort != 0 {\n\t\t\tif rule.HostSocket != \"\" {\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.hostPort` must be 0 when field `%s.hostSocket` is set\", field, field))\n\t\t\t}\n\t\t\tif rule.HostPort != rule.HostPortRange[0] {\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.hostPort` must match field `%s.hostPortRange[0]`\", field, field))\n\t\t\t}\n\t\t\t// redundant validation to make sure the error contains the correct field name\n\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))","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/limayaml/validate.go#L311-L347","documentation":"The validator requires that when a portForward rule specifies an explicit HostPort, it equals HostPortRange[0]. HostPort is a convenience duplicate of the range start; if they disagree the rule is internally inconsistent. This catches rules where the scalar and range forms were edited independently.","triggerScenarios":"Validate on a LimaYAML where portForwards[i].HostPort != 0 and HostPort != HostPortRange[0] — e.g. hostPort: 8080 with hostPortRange: [9090, 9091].","commonSituations":"Changing hostPortRange but forgetting the standalone hostPort field; generating YAML programmatically where the range is computed but the scalar copied from an old value; typos in one of the two fields.","solutions":["Set hostPort equal to the first element of hostPortRange","Or drop hostPort entirely and rely on hostPortRange alone","Or drop hostPortRange and express a single port with hostPort plus a matching hostPortRange [n, n]"],"exampleFix":"// before\nportForwards:\n  - guestPort: 80\n    hostPort: 8080\n    hostPortRange: [9090, 9091]\n// after\nportForwards:\n  - guestPort: 80\n    hostPort: 8080\n    hostPortRange: [8080, 8080]","handlingStrategy":"validation","validationCode":"for i, rule := range y.PortForwards {\n  if rule.HostPort != 0 && rule.HostPort != rule.HostPortRange[0] {\n    return fmt.Errorf(\"portForwards[%d]: hostPort must equal hostPortRange[0]\", i)\n  }\n}","typeGuard":"func hostPortConsistent(rule limatype.PortForward) bool { return rule.HostPort == 0 || rule.HostPort == rule.HostPortRange[0] }","tryCatchPattern":"if err := limayaml.Validate(y, false); err != nil {\n  if strings.Contains(err.Error(), \"must match field\") && strings.Contains(err.Error(), \"hostPortRange[0]\") {\n    // sync hostPort with hostPortRange[0]\n  }\n}","preventionTips":["Prefer expressing rules with hostPortRange only and derive hostPort","Never edit hostPort and hostPortRange independently","Generate the scalar from the range in any config-generation code"],"tags":["lima","port-forwarding","config-validation"],"backgroundTag":"port-forward-config-conflict","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}