{"record":{"id":"158775e4ddcb0282","repo":"wavetermdev/waveterm","slug":"error-encoding-env-vars-w","errorCode":null,"errorMessage":"error encoding env vars: %w","messagePattern":"error encoding env vars: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-token.go","lineNumber":40,"sourceCode":"}\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}\n","sourceCodeStart":22,"sourceCodeEnd":46,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-token.go#L22-L46","documentation":"After the RPC client is set up, wsh encodes the returned environment variables into shell-specific script text via shellutil.EncodeEnvVarsForShell. An unsupported or unrecognized shell type makes encoding fail, wrapped with this message.","triggerScenarios":"EncodeEnvVarsForShell(shellType, env) returning an error because shellType isn't one of the supported encoders (bash/zsh/powershell/cmd etc.), or an env value cannot be encoded.","commonSituations":"Typo in the shell type argument (`wsh token <tok> bsh`); passing a full path like /bin/bash instead of a shell name; a shell variant the encoder doesn't know.","solutions":["Use a supported shell name exactly: bash, zsh, powershell, or cmd — not a path or misspelling.","Run `wsh token --help` to see accepted shell types.","Strip any directory prefix from the shell argument (e.g. use `bash`, not `/usr/bin/bash`)."],"exampleFix":"// before\nwsh token abc123 /usr/bin/zsh\n// after\nwsh token abc123 zsh","handlingStrategy":"validation","validationCode":"# validate shell type before invoking\ncase \"$SHELLTYPE\" in\n  bash|zsh|powershell|cmd) ;;\n  *) echo \"unsupported shell type: $SHELLTYPE\"; exit 1 ;;\nesac\nwsh token \"$TOKEN\" \"$SHELLTYPE\"","typeGuard":null,"tryCatchPattern":"envScriptText, err := shellutil.EncodeEnvVarsForShell(shellType, rtnData.Env)\nif err != nil {\n\t// fall back to a default known shell type and retry once\n\tenvScriptText, retryErr := shellutil.EncodeEnvVarsForShell(\"bash\", rtnData.Env)\n\tif retryErr != nil {\n\t\treturn fmt.Errorf(\"error encoding env vars: %w\", retryErr)\n\t}\n\t_ = envScriptText\n}","preventionTips":["Pass bare shell names (bash, zsh, powershell, cmd), never full paths.","Derive the shell type via `basename \"$SHELL\"` if reusing $SHELL.","Pin the shell type in scripts instead of inferring it from the environment."],"tags":["cli","shell","encoding"],"backgroundTag":"unsupported-shell-type","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}