derailed/k9s · warning

unable to parse selection %s

Error message

unable to parse selection %s

What it means

pfToHuman() parses a port-forward table selection with selRx: protocol/name|container|localPort:remotePort ([\w-]+/[\w-]+|[\w-]?|digits:digits anchored at start). If the selection does not match — a segment contains characters outside [\w-] (dots, colons, slashes beyond the single separator) or the port pair is missing/non-numeric — FindStringSubmatch returns fewer than 6 groups and this error flashes, aborting the delete-confirm dialog.

Source

Thrown at internal/view/pf.go:200

				return
			}
		}
		p.App().Flash().Infof("Successfully deleted %d PortForward!", len(selections))
		p.GetTable().Refresh()
	}, func() {})

	return nil
}

// ----------------------------------------------------------------------------
// Helpers...

var selRx = regexp.MustCompile(`\A([\w-]+)/([\w-]+)\|([\w-]+)?\|(\d+):(\d+)`)

func pfToHuman(s string) (string, error) {
	mm := selRx.FindStringSubmatch(s)
	if len(mm) < 6 {
		return "", fmt.Errorf("unable to parse selection %s", s)
	}

	return fmt.Sprintf("%s::%s %s->%s", mm[2], mm[3], mm[4], mm[5]), nil
}

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

  1. Delete the port-forward out-of-band if k9s cannot parse it: kubectl delete pod/... or remove the PF target, then refresh the :pf view
  2. Prefer resource names that are DNS-1123 labels ([a-zA-Z0-9-]) for objects you port-forward
  3. Upgrade k9s — the selection format/regex has been tightened over releases; stale formats from old versions are handled by newer builds
Defensive patterns

Strategy: validation

Validate before calling

// validate the selection shape before using it
var selRx = regexp.MustCompile(`\A([\w-]+)/([\w-]+)\|([\w-]+)?\|(\d+):(\d+)`)

if !selRx.MatchString(s) {
    return "", fmt.Errorf("selection %q is malformed — refresh the :pf view or delete via kubectl", s)
}

Prevention

When it happens

Trigger: Deleting a port-forward whose stored selection string has a pod/service name with dots (DNS subdomains allow them, the regex does not), an empty local:remote pair, or any malformed row from the PF DAO; the caller (pf.go deleteCmd) flashes the error and returns without a dialog.

Common situations: Resources named with dots (my.app.svc) or other non-[\w-] characters in PF'd objects; older PF entries persisted in a different format after a k9s upgrade; manual edits to the PF config file.

Understand the failure class

Related errors


AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15). Data as JSON: /api/errors/e41f1e9c20642053. Report an issue: GitHub.