{"record":{"id":"fb6c49772e453bef","repo":"lima-vm/lima","slug":"field-s-guestport-must-match-field-s-guestpor","errorCode":null,"errorMessage":"field `%s.guestPort` must match field `%s.guestPortRange[0]`","messagePattern":"field `(.+?)\\.guestPort` must match field `(.+?)\\.guestPortRange\\[0\\]`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/limayaml/validate.go","lineNumber":317,"sourceCode":"\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `probe[%d].script` must start with a '#!' line\", i))\n\t\t}\n\t\tswitch p.Mode {\n\t\tcase limatype.ProbeModeReadiness:\n\t\tdefault:\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `probe[%d].mode` can only be %#q\", i, limatype.ProbeModeReadiness))\n\t\t}\n\t}\n\tfor i, rule := range y.PortForwards {\n\t\tfield := fmt.Sprintf(\"portForwards[%d]\", i)\n\t\tif *rule.GuestIPMustBeZero && !rule.GuestIP.Equal(net.IPv4zero) {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `%s.guestIPMustBeZero` can only be true when field `%s.guestIP` is 0.0.0.0\", field, field))\n\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}","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/limayaml/validate.go#L299-L335","documentation":"Same consistency rule as the guestPort/guestPortRange mismatch: when a specific `guestPort` is set on a portForward rule it must equal `guestPortRange[0]`. The error text names both fields with the rule index interpolated, e.g. `portForwards[2].guestPort must match portForwards[2].guestPortRange[0]`.","triggerScenarios":"Same as the scalar/range inconsistency: validating a config where rule.GuestPort != rule.GuestPortRange[0]; the dedicated message exists (see the redundant-validation comment in the source) so the field name is guaranteed to appear in the error.","commonSituations":"Hand-edited lima.yaml combining guestPort and guestPortRange with diverging values; Go code constructing rules without running limayaml defaulting; diff merges that updated one field only.","solutions":["Align guestPortRange[0] with guestPort (or drop guestPortRange)","Re-run the config through limactl's load/default pipeline so the fields are normalized","Remove guestPort entirely when forwarding a range via guestPortRange"],"exampleFix":"// before\nportForwards:\n- guestPort: 3000\n  guestPortRange: [3001, 3005]\n  hostPortRange: [3001, 3005]\n// after\nportForwards:\n- guestPortRange: [3001, 3005]\n  hostPortRange: [3001, 3005]","handlingStrategy":"validation","validationCode":"for i, r := range cfg.PortForwards {\n    if r.GuestPort != 0 && r.GuestPort != r.GuestPortRange[0] {\n        return fmt.Errorf(\"portForwards[%d]: set either guestPort or guestPortRange, not mismatched both\", i)\n    }\n}","typeGuard":"func portRangeConsistent(start, scalar int) bool {\n    return scalar == 0 || scalar == start\n}","tryCatchPattern":null,"preventionTips":["Use guestPortRange alone for range forwards, guestPort alone for single ports","Diff-check portForwards blocks after merges/rebases","Run limactl validate as a pre-commit hook on lima.yaml changes"],"tags":["config-validation","port-forward","lima-yaml"],"backgroundTag":"schema-validation-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}