{"record":{"id":"6486db2aad1974f1","repo":"slimtoolkit/slim","slug":"podport-cannot-be-empty","errorCode":null,"errorMessage":"podPort cannot be empty","messagePattern":"podPort cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/kubernetes/kubectl.go","lineNumber":140,"sourceCode":"\t\t\"exec\", pod,\n\t\t\"--kubeconfig\", k.kubeconfig,\n\t\t\"--namespace\", namespace,\n\t\t\"--container\", container,\n\t\t\"--\", cmd,\n\t}, args...)\n\treturn exec.Command(args[0], args[1:]...).CombinedOutput()\n}\n\nfunc (k *kubectl) PortForward(\n\tctx context.Context,\n\tnamespace string,\n\tpod string,\n\taddress string,\n\thostPort string,\n\tpodPort string,\n) (*exec.Cmd, string, error) {\n\tif podPort == \"\" {\n\t\treturn nil, \"\", errors.New(\"podPort cannot be empty\")\n\t}\n\n\tmapping := \":\" + podPort\n\tif hostPort != \"\" {\n\t\tmapping = hostPort + mapping\n\t}\n\n\tcmd := exec.CommandContext(\n\t\tctx,\n\t\t\"kubectl\",\n\t\t\"--kubeconfig\", k.kubeconfig,\n\t\t\"--namespace\", namespace,\n\t\t\"--address\", address,\n\t\t\"port-forward\", \"pod/\"+pod, mapping,\n\t)\n\n\tout, err := cmd.StdoutPipe()\n\tif err != nil {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/kubernetes/kubectl.go#L122-L158","documentation":"PortForward wraps `kubectl port-forward` and validates its inputs before exec'ing. A pod port is mandatory — without it kubectl has nothing to forward to — so an empty podPort is rejected immediately.","triggerScenarios":"Calling PortForward (public) with podPort set to \"\" — e.g. an unset/empty config field or an unparsed port variable passed through.","commonSituations":"Config file missing the target port; environment variable not set; parsing failure upstream silently yielding an empty string.","solutions":["Pass a non-empty podPort (e.g. \"8080\") to PortForward","Validate the port value at config load time before invoking PortForward","Log/inspect where the port is derived from and fix the empty source"],"exampleFix":"// before\nk.PortForward(ctx, pod, addr, hostPort, port) // port == \"\"\n// after\nif port == \"\" { port = \"8080\" }\nk.PortForward(ctx, pod, addr, hostPort, port)","handlingStrategy":"validation","validationCode":"if podPort == \"\" { return errors.New(\"podPort is required before calling PortForward\") }\nif _, err := strconv.Atoi(podPort); err != nil { return fmt.Errorf(\"podPort %q is not numeric\", podPort) }","typeGuard":null,"tryCatchPattern":"cmd, hp, err := k.PortForward(ctx, pod, addr, hostPort, podPort)\nif err != nil && strings.Contains(err.Error(), \"podPort cannot be empty\") {\n  return fmt.Errorf(\"config error: target port missing for pod %s\", pod)\n}","preventionTips":["Validate port fields at config-load time","Never pass raw env vars without empty checks","Fail fast with clear messages when parsing ports"],"tags":["kubernetes","port-forward","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}