wavetermdev/waveterm · error

error encoding env vars: %w

Error message

error encoding env vars: %w

What it means

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.

Source

Thrown at cmd/wsh/cmd/wshcmd-token.go:40

}

func tokenCmdRun(cmd *cobra.Command, args []string) (rtnErr error) {
	if len(args) != 2 {
		OutputHelpMessage(cmd)
		return fmt.Errorf("wsh token requires exactly 2 arguments, got %d", len(args))
	}
	tokenStr, shellType := args[0], args[1]
	if tokenStr == "" || shellType == "" {
		OutputHelpMessage(cmd)
		return fmt.Errorf("wsh token requires non-empty arguments")
	}
	rtnData, err := setupRpcClientWithToken(tokenStr)
	if err != nil {
		return fmt.Errorf("error setting up rpc client: %w", err)
	}
	envScriptText, err := shellutil.EncodeEnvVarsForShell(shellType, rtnData.Env)
	if err != nil {
		return fmt.Errorf("error encoding env vars: %w", err)
	}
	WriteStdout("%s\n", envScriptText)
	WriteStdout("%s\n", rtnData.InitScriptText)
	return nil
}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Use a supported shell name exactly: bash, zsh, powershell, or cmd — not a path or misspelling.
  2. Run `wsh token --help` to see accepted shell types.
  3. Strip any directory prefix from the shell argument (e.g. use `bash`, not `/usr/bin/bash`).

Example fix

// before
wsh token abc123 /usr/bin/zsh
// after
wsh token abc123 zsh
Defensive patterns

Strategy: validation

Validate before calling

# validate shell type before invoking
case "$SHELLTYPE" in
  bash|zsh|powershell|cmd) ;;
  *) echo "unsupported shell type: $SHELLTYPE"; exit 1 ;;
esac
wsh token "$TOKEN" "$SHELLTYPE"

Try / catch

envScriptText, err := shellutil.EncodeEnvVarsForShell(shellType, rtnData.Env)
if err != nil {
	// fall back to a default known shell type and retry once
	envScriptText, retryErr := shellutil.EncodeEnvVarsForShell("bash", rtnData.Env)
	if retryErr != nil {
		return fmt.Errorf("error encoding env vars: %w", retryErr)
	}
	_ = envScriptText
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/158775e4ddcb0282. Report an issue: GitHub.