{"record":{"id":"0643899e3d2d272d","repo":"wavetermdev/waveterm","slug":"wsh-token-requires-exactly-2-arguments-got-d","errorCode":null,"errorMessage":"wsh token requires exactly 2 arguments, got %d","messagePattern":"wsh token requires exactly 2 arguments, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-token.go","lineNumber":27,"sourceCode":"\t\"github.com/spf13/cobra\"\n\t\"github.com/wavetermdev/waveterm/pkg/util/shellutil\"\n)\n\nvar tokenCmd = &cobra.Command{\n\tUse:    \"token [token] [shell-type]\",\n\tShort:  \"exchange token for shell initialization script\",\n\tRunE:   tokenCmdRun,\n\tHidden: true,\n}\n\nfunc init() {\n\trootCmd.AddCommand(tokenCmd)\n}\n\nfunc tokenCmdRun(cmd *cobra.Command, args []string) (rtnErr error) {\n\tif len(args) != 2 {\n\t\tOutputHelpMessage(cmd)\n\t\treturn fmt.Errorf(\"wsh token requires exactly 2 arguments, got %d\", len(args))\n\t}\n\ttokenStr, shellType := args[0], args[1]\n\tif tokenStr == \"\" || shellType == \"\" {\n\t\tOutputHelpMessage(cmd)\n\t\treturn fmt.Errorf(\"wsh token requires non-empty arguments\")\n\t}\n\trtnData, err := setupRpcClientWithToken(tokenStr)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error setting up rpc client: %w\", err)\n\t}\n\tenvScriptText, err := shellutil.EncodeEnvVarsForShell(shellType, rtnData.Env)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error encoding env vars: %w\", err)\n\t}\n\tWriteStdout(\"%s\\n\", envScriptText)\n\tWriteStdout(\"%s\\n\", rtnData.InitScriptText)\n\treturn nil\n}","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-token.go#L9-L45","documentation":"`wsh token` requires exactly two arguments: the token string and the shell type. Cobra passes whatever the user typed, and tokenCmdRun enforces len(args) == 2, printing help and returning this error otherwise.","triggerScenarios":"Running `wsh token` with zero, one, or three-plus arguments — e.g. omitting the shell type, or quoting mistakes that split/merge arguments.","commonSituations":"Forgetting the second argument (token only); including an extra flag-like word; shell quoting collapsing or expanding arguments unexpectedly.","solutions":["Supply exactly two arguments: `wsh token <token> <shelltype>` (e.g. `wsh token abc123 bash`).","Run `wsh token --help` to see the expected usage.","Check shell quoting if arguments contain spaces or special characters."],"exampleFix":"// before\nwsh token mytoken\n// after\nwsh token mytoken bash","handlingStrategy":"validation","validationCode":"# check argument count before invoking\nif [ \"$#\" -ne 2 ]; then echo \"usage: wsh token <token> <shelltype>\"; exit 1; fi\nwsh token \"$@\"","typeGuard":null,"tryCatchPattern":"// in scripts, capture and branch on the error\nif ! wsh token \"$TOKEN\" \"$SHELLTYPE\"; then\n\techo \"wsh token failed: expected exactly 2 arguments\" >&2\n\texit 1\nfi","preventionTips":["Always pass token and shell type together in that order.","Quote arguments so spaces don't split or merge them.","Check `wsh token --help` when unsure of usage."],"tags":["cli","argument-validation","cobra"],"backgroundTag":"invalid-cli-argument","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}