derailed/k9s · error
no connection available
Error message
no connection available
What it means
xrayCmd needs the alias resolver (c.alias) to map its argument to a GVR, but c.alias is nil — the view has no active cluster connection. The alias map is built from the live cluster's discovery/RESTMapper, so it exists only once a connection is established.
Source
Thrown at internal/view/command.go:152
return false
}
func (c *Command) aliasCmd(p *cmd.Interpreter, pushCmd bool) error {
filter, _ := p.FilterArg()
v := NewAlias(client.AliGVR)
v.SetFilter(filter, true)
return c.exec(p, client.AliGVR, v, false, pushCmd)
}
func (c *Command) xrayCmd(p *cmd.Interpreter, pushCmd bool) error {
arg, cns, ok := p.XrayArgs()
if !ok {
return errors.New("invalid command. use `xray xxx`")
}
if c.alias == nil {
return fmt.Errorf("no connection available")
}
gvr, ok := c.alias.Resolve(cmd.NewInterpreter(arg))
if !ok {
return fmt.Errorf("invalid resource name: %q", arg)
}
if !allowedXRay(gvr) {
return fmt.Errorf("unsupported resource %q", arg)
}
ns := c.app.Config.ActiveNamespace()
if cns != "" {
ns = cns
}
if err := c.app.Config.SetActiveNamespace(client.CleanseNamespace(ns)); err != nil {
return err
}
if err := c.app.switchNS(ns); err != nil {
return err
}View on GitHub (pinned to 2d3ccc6ba2)
Solutions
- Establish a connection first: use `context <name>` to select a working kube context and wait for the dashboard.
- Validate kubectl connectivity out-of-band: kubectl get --raw /api on the intended context.
- Re-enter the xray command once the cluster view has loaded (alias initialized).
- If it persists on a healthy cluster, check that the kubeconfig context/cluster entries parse (KUBECONFIG env, yaml validity).
Defensive patterns
Strategy: validation
Validate before calling
if c.alias == nil {
return fmt.Errorf("not connected: select a context first (context <name>)")
}
gvr, ok := c.alias.Resolve(cmd.NewInterpreter(arg)) Type guard
func (c *Command) connected() bool { return c.alias != nil } Try / catch
if err := c.xrayCmd(p, push); err != nil {
if strings.Contains(err.Error(), "no connection") {
c.app.Flash().Err(err) // guide user to connect; do not auto-retry
}
} Prevention
- Issue cluster commands only after the dashboard/context view has fully loaded.
- Validate connectivity (kubectl get --raw /api) after context switches and credential renewals.
- Guard all alias-dependent commands behind a nil check with a connect-first hint.
When it happens
Trigger: Running `xray <resource>` before any cluster context is active, after the connection dropped (apiserver restart, VPN loss, token expiry), or in embedded/headless mode where no factory connection was created.
Common situations: Startup race: issuing xray immediately at app start before the context loads; kubeconfig pointing at an unreachable cluster; expired credentials so initialization failed silently leaving alias nil.
Related errors
- ACCESS -- No API server connection
- dialLogs - no connection to dial
- no connection to dial
- no connection to cached dial
- no active context available
AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15).
Data as JSON: /api/errors/d7e7a5af88e903b2.
Report an issue: GitHub.