{"record":{"id":"dc7bbdfa0f36768e","repo":"derailed/k9s","slug":"container-to-local-port-mismatch","errorCode":null,"errorMessage":"container to local port mismatch","messagePattern":"container to local port mismatch","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/view/pf_dialog.go","lineNumber":75,"sourceCode":"\t\tp2 = p\n\t})\n\tif loField.GetText() == \"\" {\n\t\tloField.SetPlaceholder(\"Enter a local port\")\n\t}\n\taddress := v.App().Config.K9s.PortForwardAddress\n\tf.AddInputField(\"Address:\", address, fieldLen, nil, func(h string) {\n\t\taddress = h\n\t})\n\tfor i := range 3 {\n\t\tif field, ok := f.GetFormItem(i).(*tview.InputField); ok {\n\t\t\tfield.SetLabelColor(styles.LabelFgColor.Color())\n\t\t\tfield.SetFieldTextColor(styles.FieldFgColor.Color())\n\t\t}\n\t}\n\n\tf.AddButton(\"OK\", func() {\n\t\tif coField.GetText() == \"\" || loField.GetText() == \"\" {\n\t\t\tv.App().Flash().Err(fmt.Errorf(\"container to local port mismatch\"))\n\t\t\treturn\n\t\t}\n\t\ttt, err := port.ToTunnels(address, coField.GetText(), loField.GetText())\n\t\tif err != nil {\n\t\t\tv.App().Flash().Err(err)\n\t\t\treturn\n\t\t}\n\t\tif err := okFn(v, path, tt); err != nil {\n\t\t\tv.App().Flash().Err(err)\n\t\t}\n\t})\n\tpages := v.App().Content.Pages\n\tf.AddButton(\"Cancel\", func() {\n\t\tDismissPortForwards(v, pages)\n\t})\n\tfor i := range 2 {\n\t\tif b := f.GetButton(i); b != nil {\n\t\t\tb.SetBackgroundColorActivated(styles.ButtonFocusBgColor.Color())","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/view/pf_dialog.go#L57-L93","documentation":"Thrown by the k9s port-forward dialog's OK handler when either the Container Port or Local Port input field is left empty. Despite the wording 'mismatch', the check in internal/view/pf_dialog.go:74 only compares the two fields to the empty string — no actual comparison between container and local port is performed. The message is therefore misleading: it fires on blank input, not on a real mismatch.","triggerScenarios":"Pressing OK in the <PortForward> modal with an empty 'Container Port:' field (expected format 'containerName::port') or an empty 'Local Port:' field. Happens when the pod exposes no container ports (so no prefill via PreferredPorts/ToPortSpec) or the user clears the fields before confirming.","commonSituations":"Port-forwarding a pod that declares no containerPort in its spec; a dialog opened with placeholders ('Enter a container name::port', 'Enter a local port') instead of values; users who expect k9s to default the local port automatically.","solutions":["Fill the Container Port field with a 'containerName::port' spec (e.g. 'web::8080') and the Local Port field with a free local port number, then press OK","If unsure of the container name/port, check the pod spec (kubectl get pod <name> -o yaml | grep -A4 ports) and use that container name and containerPort","Pick a local port that is not already bound (e.g. avoid ports listed by 'ss -ltn')","Treat the message as 'empty port field' — if both fields are visibly filled and you still see it, report the misleading message upstream"],"exampleFix":"// before (user leaves Local Port blank and hits OK)\n// -> Flash error: container to local port mismatch\n\n// after: fill dialog fields\n// Container Port: web::8080\n// Local Port:    8080\n// Address:       127.0.0.1\n// press OK -> port.ToTunnels(address, \"web::8080\", \"8080\") succeeds","handlingStrategy":"validation","validationCode":"// in the OK handler, validate both fields before proceeding\nco, lo := strings.TrimSpace(coField.GetText()), strings.TrimSpace(loField.GetText())\nif co == \"\" || lo == \"\" {\n    v.App().Flash().Err(fmt.Errorf(\"container port and local port are both required\"))\n    return\n}\n// optional: pre-check the container::port shape\nif !strings.Contains(co, \"::\") {\n    v.App().Flash().Err(fmt.Errorf(\"container port must be name::port, got %q\", co))\n    return\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-fill the dialog from pod containerPort specs (PreferredPorts/ToPortSpec already do this when the pod declares ports)","Keep the placeholders ('Enter a container name::port') visible so empty fields are obvious before pressing OK","Use the coField ChangedFunc which auto-syncs the local port as you type the container spec"],"tags":["k9s","port-forward","ui-validation","tview","dialog"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}