slimtoolkit/slim · error
podPort cannot be empty
Error message
podPort cannot be empty
What it means
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.
Source
Thrown at pkg/app/master/kubernetes/kubectl.go:140
"exec", pod,
"--kubeconfig", k.kubeconfig,
"--namespace", namespace,
"--container", container,
"--", cmd,
}, args...)
return exec.Command(args[0], args[1:]...).CombinedOutput()
}
func (k *kubectl) PortForward(
ctx context.Context,
namespace string,
pod string,
address string,
hostPort string,
podPort string,
) (*exec.Cmd, string, error) {
if podPort == "" {
return nil, "", errors.New("podPort cannot be empty")
}
mapping := ":" + podPort
if hostPort != "" {
mapping = hostPort + mapping
}
cmd := exec.CommandContext(
ctx,
"kubectl",
"--kubeconfig", k.kubeconfig,
"--namespace", namespace,
"--address", address,
"port-forward", "pod/"+pod, mapping,
)
out, err := cmd.StdoutPipe()
if err != nil {View on GitHub (pinned to 81940d17fa)
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
Example fix
// before
k.PortForward(ctx, pod, addr, hostPort, port) // port == ""
// after
if port == "" { port = "8080" }
k.PortForward(ctx, pod, addr, hostPort, port) Defensive patterns
Strategy: validation
Validate before calling
if podPort == "" { return errors.New("podPort is required before calling PortForward") }
if _, err := strconv.Atoi(podPort); err != nil { return fmt.Errorf("podPort %q is not numeric", podPort) } Try / catch
cmd, hp, err := k.PortForward(ctx, pod, addr, hostPort, podPort)
if err != nil && strings.Contains(err.Error(), "podPort cannot be empty") {
return fmt.Errorf("config error: target port missing for pod %s", pod)
} Prevention
- Validate port fields at config-load time
- Never pass raw env vars without empty checks
- Fail fast with clear messages when parsing ports
When it happens
Trigger: Calling PortForward (public) with podPort set to "" — e.g. an unset/empty config field or an unparsed port variable passed through.
Common situations: Config file missing the target port; environment variable not set; parsing failure upstream silently yielding an empty string.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- cannot detect host port
- found more than 1 workload '%s/%s' match in the supplied man
- Pod terminated
- Pod not running
- Container terminated
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/6486db2aad1974f1.
Report an issue: GitHub.