wavetermdev/waveterm · error
requires a key argument
Error message
requires a key argument
What it means
Without --all, `wsh getvar` requires exactly one positional key naming the variable to read. When len(args) != 1, getVarRun prints the command help via OutputHelpMessage and returns this error (cmd/wshcmd-getvar.go:82). It enforces the command's argument contract before any RPC is made.
Source
Thrown at cmd/wsh/cmd/wshcmd-getvar.go:82
blockArg = "client"
}
}
fullORef, err := resolveBlockArg()
if err != nil {
return err
}
if getVarAllVars {
if len(args) > 0 {
return fmt.Errorf("cannot specify key with --all")
}
return getAllVariables(fullORef.OID)
}
// Single variable case - existing logic
if len(args) != 1 {
OutputHelpMessage(cmd)
return fmt.Errorf("requires a key argument")
}
key := args[0]
commandData := wshrpc.CommandVarData{
Key: key,
ZoneId: fullORef.OID,
FileName: getVarFileName,
}
resp, err := wshclient.GetVarCommand(RpcClient, commandData, &wshrpc.RpcOpts{Timeout: 2000})
if err != nil {
return fmt.Errorf("getting variable: %w", err)
}
if !resp.Exists {
WshExitCode = 1
return nil
}View on GitHub (pinned to a4447c1563)
Solutions
- Pass exactly one key: `wsh getvar FOO`
- Use `wsh getvar --all` if you want every variable instead of one
- Check the Read the docs output from OutputHelpMessage to confirm flag/value pairing (e.g. --varfile <name>)
Example fix
// before wsh getvar // after wsh getvar FOO
Defensive patterns
Strategy: validation
Validate before calling
[ $# -eq 1 ] || { echo 'usage: wsh getvar <key>'; exit 2; } Prevention
- Always supply exactly one key unless using --all
- Beware flags that swallow values (e.g. --varfile needs a value) leaving no positional arg
- Quote the key to prevent shell splitting into multiple args
When it happens
Trigger: Running bare `wsh getvar`, or passing zero or multiple positional args such as `wsh getvar FOO BAR` without --all.
Common situations: Forgetting the key in a script after refactoring; accidentally passing flags that consume values (e.g. --varfile without a value) leaving no positional arg; shell splitting removing an empty quoted key.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- cannot specify key with --all
- no files or message provided
- too many files (maximum %d files allowed)
- stdin (-) can only be used once
- WAVETERM_TABID environment variable not set
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/ea00ef74d87ee48a.
Report an issue: GitHub.