{"record":{"id":"7ca341bbd44f945b","repo":"derailed/k9s","slug":"invalid-command-use-xray-xxx","errorCode":null,"errorMessage":"invalid command. use `xray xxx`","messagePattern":"invalid command\\. use `xray xxx`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/view/command.go","lineNumber":149,"sourceCode":"\t\tp.SwitchNS(ns)\n\t}\n\n\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}","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/view/command.go#L131-L167","documentation":"Returned by `Command.xrayCmd` (internal/view/command.go:~149) when the command interpreter reports no argument for the `xray` command (`p.XrayArgs()` returns ok=false). k9s' xray view needs a resource name to traverse, so `xray` with no target is rejected before anything else runs. Subsequent guards (alias resolution, allowlist) produce their own errors; this one is purely the missing-argument case.","triggerScenarios":"Typing `:xray` and hitting enter in the command prompt with no argument, or a command alias that expands to bare `xray`. `cmd.Interpreter.XrayArgs()` fails to extract the resource token.","commonSituations":"New users exploring `:xray` without knowing it takes an argument; typos like `:xray` instead of `:xray po`; scripts/aliases configured with a bare xray.","solutions":["Provide a resource: `:xray po`, `:xray deploy`, `:xray svc`, `:xray ns`","Check allowed targets with allowedXRay if unsure which resources the current k9s version supports","Fix any custom alias that invokes xray without its argument"],"exampleFix":"# before\n:xray\n# -> invalid command. use `xray xxx`\n# after\n:xray deploy","handlingStrategy":"validation","validationCode":"// Verify the argument exists before dispatching:\nif len(strings.Fields(cmdString)) < 2 || !strings.HasPrefix(cmdString, \"xray \") {\n    return errors.New(\"invalid command. use `xray xxx`\")\n}","typeGuard":"func hasXrayArg(args []string) bool {\n    return len(args) >= 1 && strings.TrimSpace(args[0]) != \"\"\n}","tryCatchPattern":null,"preventionTips":["Always pass a resource token to :xray (po, deploy, svc, ns)","Pre-validate user command strings in wrappers","Show allowed xray targets in help text"],"tags":["cli","usage","xray","k9s"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}