{"record":{"id":"f3f5b5e122b5cfda","repo":"wavetermdev/waveterm","slug":"command-q-expected-d-args-got-d","errorCode":null,"errorMessage":"command %q expected %d args, got %d","messagePattern":"command %q expected (.+?) args, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshutil/wshadapter.go","lineNumber":123,"sourceCode":"\t\t\tcmdData, err := recodeCommandData(cmd, handler.GetCommandRawData(), commandDataTypes[0])\n\t\t\tif err != nil {\n\t\t\t\thandler.SendResponseError(err)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tcallParams = append(callParams, reflect.ValueOf(cmdData))\n\t\t} else if len(commandDataTypes) > 1 {\n\t\t\tmultiArgAny, err := recodeCommandData(cmd, handler.GetCommandRawData(), multiArgRType)\n\t\t\tif err != nil {\n\t\t\t\thandler.SendResponseError(err)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tmultiArg, ok := multiArgAny.(wshrpc.MultiArg)\n\t\t\tif !ok {\n\t\t\t\thandler.SendResponseError(fmt.Errorf(\"command %q invalid multi arg payload\", cmd))\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif len(multiArg.Args) != len(commandDataTypes) {\n\t\t\t\thandler.SendResponseError(fmt.Errorf(\"command %q expected %d args, got %d\", cmd, len(commandDataTypes), len(multiArg.Args)))\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tfor idx, commandDataType := range commandDataTypes {\n\t\t\t\tcmdData, err := recodeCommandData(cmd, multiArg.Args[idx], commandDataType)\n\t\t\t\tif err != nil {\n\t\t\t\t\thandler.SendResponseError(err)\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tcallParams = append(callParams, reflect.ValueOf(cmdData))\n\t\t\t}\n\t\t}\n\t\tif methodDecl.CommandType == wshrpc.RpcType_Call {\n\t\t\trtnVals := implMethod.Call(callParams)\n\t\t\trtnData, rtnErr := decodeRtnVals(rtnVals)\n\t\t\tif rtnErr != nil {\n\t\t\t\thandler.SendResponseError(rtnErr)\n\t\t\t\treturn true\n\t\t\t}","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshutil/wshadapter.go#L105-L141","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the expected count from the error message and pad/trim MultiArg.Args accordingly (use nil/zero values for placeholder args if required positionally).","Consult the command's declaration (WshCommandDeclMap / GetCommandDataTypes) for the authoritative argument list and order.","Sync client and server versions if the command signature recently changed."],"exampleFix":"// before: 2 args where 3 are declared\npayload := wshrpc.MultiArg{Args: []any{scope, varName}}\n// after: provide every declared arg in order\npayload := wshrpc.MultiArg{Args: []any{scope, varName, value}}","handlingStrategy":"validation","validationCode":"decl := wshutil.WshCommandDeclMap[cmd]\nif decl != nil && len(multiArg.Args) != len(decl.GetCommandDataTypes()) {\n    return fmt.Errorf(\"%s expects %d args, got %d\", cmd,\n        len(decl.GetCommandDataTypes()), len(multiArg.Args))\n}","typeGuard":null,"tryCatchPattern":"err := client.SendRpcRequest(ctx, cmd, multiArg)\nif err != nil && strings.Contains(err.Error(), \"expected\") && strings.Contains(err.Error(), \"args, got\") {\n    return fmt.Errorf(\"wrong arity for %s: %w\", cmd, err)\n}","preventionTips":["Derive arg count from the command declaration, not from call sites.","Re-check payload construction after any client/server upgrade.","Use nil placeholders for positional args you do not need rather than omitting them."],"tags":["rpc","wsh","payload","arity","waveterm"],"backgroundTag":"rpc-argument-count-mismatch","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}