{"record":{"id":"d7e7a5af88e903b2","repo":"derailed/k9s","slug":"no-connection-available","errorCode":null,"errorMessage":"no connection available","messagePattern":"no connection available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/view/command.go","lineNumber":152,"sourceCode":"\treturn false\n}\n\nfunc (c *Command) aliasCmd(p *cmd.Interpreter, pushCmd bool) error {\n\tfilter, _ := p.FilterArg()\n\n\tv := NewAlias(client.AliGVR)\n\tv.SetFilter(filter, true)\n\n\treturn c.exec(p, client.AliGVR, v, false, pushCmd)\n}\n\nfunc (c *Command) xrayCmd(p *cmd.Interpreter, pushCmd bool) error {\n\targ, cns, ok := p.XrayArgs()\n\tif !ok {\n\t\treturn errors.New(\"invalid command. use `xray xxx`\")\n\t}\n\tif c.alias == nil {\n\t\treturn fmt.Errorf(\"no connection available\")\n\t}\n\tgvr, ok := c.alias.Resolve(cmd.NewInterpreter(arg))\n\tif !ok {\n\t\treturn fmt.Errorf(\"invalid resource name: %q\", arg)\n\t}\n\tif !allowedXRay(gvr) {\n\t\treturn fmt.Errorf(\"unsupported resource %q\", arg)\n\t}\n\tns := c.app.Config.ActiveNamespace()\n\tif cns != \"\" {\n\t\tns = cns\n\t}\n\tif err := c.app.Config.SetActiveNamespace(client.CleanseNamespace(ns)); err != nil {\n\t\treturn err\n\t}\n\tif err := c.app.switchNS(ns); err != nil {\n\t\treturn err\n\t}","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/view/command.go#L134-L170","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if c.alias == nil {\n    return fmt.Errorf(\"not connected: select a context first (context <name>)\")\n}\ngvr, ok := c.alias.Resolve(cmd.NewInterpreter(arg))","typeGuard":"func (c *Command) connected() bool { return c.alias != nil }","tryCatchPattern":"if err := c.xrayCmd(p, push); err != nil {\n    if strings.Contains(err.Error(), \"no connection\") {\n    c.app.Flash().Err(err) // guide user to connect; do not auto-retry\n    }\n}","preventionTips":["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."],"tags":["kubernetes","connection","xray","startup"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}