wavetermdev/waveterm · error

command %q expected %d args, got %d

Error message

command %q expected %d args, got %d

What it means

For MultiArg commands, after asserting the payload is a MultiArg the adapter verifies that the number of Args equals the number of declared command data types (GetCommandDataTypes). An arity mismatch produces this error, which reports both the expected and actual argument counts. It enforces the declared RPC signature.

Source

Thrown at pkg/wshutil/wshadapter.go:123

			cmdData, err := recodeCommandData(cmd, handler.GetCommandRawData(), commandDataTypes[0])
			if err != nil {
				handler.SendResponseError(err)
				return true
			}
			callParams = append(callParams, reflect.ValueOf(cmdData))
		} else if len(commandDataTypes) > 1 {
			multiArgAny, err := recodeCommandData(cmd, handler.GetCommandRawData(), multiArgRType)
			if err != nil {
				handler.SendResponseError(err)
				return true
			}
			multiArg, ok := multiArgAny.(wshrpc.MultiArg)
			if !ok {
				handler.SendResponseError(fmt.Errorf("command %q invalid multi arg payload", cmd))
				return true
			}
			if len(multiArg.Args) != len(commandDataTypes) {
				handler.SendResponseError(fmt.Errorf("command %q expected %d args, got %d", cmd, len(commandDataTypes), len(multiArg.Args)))
				return true
			}
			for idx, commandDataType := range commandDataTypes {
				cmdData, err := recodeCommandData(cmd, multiArg.Args[idx], commandDataType)
				if err != nil {
					handler.SendResponseError(err)
					return true
				}
				callParams = append(callParams, reflect.ValueOf(cmdData))
			}
		}
		if methodDecl.CommandType == wshrpc.RpcType_Call {
			rtnVals := implMethod.Call(callParams)
			rtnData, rtnErr := decodeRtnVals(rtnVals)
			if rtnErr != nil {
				handler.SendResponseError(rtnErr)
				return true
			}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Read the expected count from the error message and pad/trim MultiArg.Args accordingly (use nil/zero values for placeholder args if required positionally).
  2. Consult the command's declaration (WshCommandDeclMap / GetCommandDataTypes) for the authoritative argument list and order.
  3. Sync client and server versions if the command signature recently changed.

Example fix

// before: 2 args where 3 are declared
payload := wshrpc.MultiArg{Args: []any{scope, varName}}
// after: provide every declared arg in order
payload := wshrpc.MultiArg{Args: []any{scope, varName, value}}
Defensive patterns

Strategy: validation

Validate before calling

decl := wshutil.WshCommandDeclMap[cmd]
if decl != nil && len(multiArg.Args) != len(decl.GetCommandDataTypes()) {
    return fmt.Errorf("%s expects %d args, got %d", cmd,
        len(decl.GetCommandDataTypes()), len(multiArg.Args))
}

Try / catch

err := client.SendRpcRequest(ctx, cmd, multiArg)
if err != nil && strings.Contains(err.Error(), "expected") && strings.Contains(err.Error(), "args, got") {
    return fmt.Errorf("wrong arity for %s: %w", cmd, err)
}

Prevention

When it happens

Trigger: Calling a multi-argument command with too few or too many entries in MultiArg.Args — e.g. omitting an optional positional argument, or appending an extra one after the command's signature changed between versions.

Common situations: Version skew where a command gained/lost a parameter; scripts copying payload shapes from an older example; writing generic RPC-forwarding code that passes the caller's args through unmodified.

Related errors


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