{"record":{"id":"8c086b7472e50ebd","repo":"derailed/k9s","slug":"invalid-command-use-context-xxx","errorCode":null,"errorMessage":"invalid command use `context xxx`","messagePattern":"invalid command use `context xxx`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/view/command.go","lineNumber":105,"sourceCode":"}\n\nvar allowedCmds = sets.New[*client.GVR](\n\tclient.PodGVR,\n\tclient.SvcGVR,\n\tclient.DpGVR,\n\tclient.DsGVR,\n\tclient.StsGVR,\n\tclient.RsGVR,\n)\n\nfunc allowedXRay(gvr *client.GVR) bool {\n\treturn allowedCmds.Has(gvr)\n}\n\nfunc (c *Command) contextCmd(p *cmd.Interpreter, pushCmd bool) error {\n\tct, ok := p.ContextArg()\n\tif !ok {\n\t\treturn fmt.Errorf(\"invalid command use `context xxx`\")\n\t}\n\n\tif ct != \"\" {\n\t\treturn useContext(c.app, ct)\n\t}\n\n\tgvr, v, comd, err := c.viewMetaFor(p)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif comd != nil {\n\t\tp = comd\n\t}\n\n\treturn c.exec(p, gvr, c.componentFor(gvr, ct, v), true, pushCmd)\n}\n\nfunc (*Command) namespaceCmd(p *cmd.Interpreter) bool {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/view/command.go#L87-L123","documentation":"The `context` command was issued but cmd.Interpreter.ContextArg() could not extract a context argument. The command grammar is `context <name>`: with a name it switches kube context immediately; with a valid-but-empty arg the code falls through to a context picker. This error means the parser got neither a name nor a valid empty-arg form.","triggerScenarios":"Typing bare `context` when the interpreter's grammar expects an argument form, or malformed input like `context   ` with odd spacing/quotes that the arg parser rejects, or programmatic invocation of contextCmd with a non-conforming interpreter line.","commonSituations":"Users accustomed to other tools where bare `context` opens the picker; typos/invisible whitespace; custom keybindings or scripts replaying a stale command line after a grammar change between versions.","solutions":["Type the full form: context <context-name> (names from kubectl config get-contexts).","To open the picker, use the documented no-arg path (e.g. :ctx alias) that satisfies the parser's empty-arg form.","If scripting, build the command via cmd.NewInterpreter with the accepted grammar instead of raw strings.","Check for stray characters/whitespace after context in the command line."],"exampleFix":"# before\n:context\n\n# after\n:context minikube","handlingStrategy":"validation","validationCode":"if _, ok := p.ContextArg(); !ok {\n    return errors.New(\"usage: context <name> (see kubectl config get-contexts)\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always type the context name with the command: context minikube.","Use the documented picker alias for the no-arg flow.","Validate command strings through the interpreter before replaying history."],"tags":["command","kubernetes-context","cli","usage"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}