{"record":{"id":"dfd7770b33932d1c","repo":"wavetermdev/waveterm","slug":"command-packets-may-not-have-datatype-set","errorCode":null,"errorMessage":"command packets may not have datatype set","messagePattern":"command packets may not have datatype set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshutil/wshrpc.go","lineNumber":169,"sourceCode":"\t\t\treturn fmt.Errorf(\"cancel packets may not have command set\")\n\t\t}\n\t\tif r.ReqId == \"\" && r.ResId == \"\" {\n\t\t\treturn fmt.Errorf(\"cancel packets must have reqid or resid set\")\n\t\t}\n\t\tif r.Data != nil {\n\t\t\treturn fmt.Errorf(\"cancel packets may not have data set\")\n\t\t}\n\t\treturn nil\n\t}\n\tif r.Command != \"\" {\n\t\tif r.ResId != \"\" {\n\t\t\treturn fmt.Errorf(\"command packets may not have resid set\")\n\t\t}\n\t\tif r.Error != \"\" {\n\t\t\treturn fmt.Errorf(\"command packets may not have error set\")\n\t\t}\n\t\tif r.DataType != \"\" {\n\t\t\treturn fmt.Errorf(\"command packets may not have datatype set\")\n\t\t}\n\t\treturn nil\n\t}\n\tif r.ReqId != \"\" {\n\t\tif r.ResId == \"\" {\n\t\t\treturn fmt.Errorf(\"request packets must have resid set\")\n\t\t}\n\t\tif r.Timeout != 0 {\n\t\t\treturn fmt.Errorf(\"non-command request packets may not have timeout set\")\n\t\t}\n\t\treturn nil\n\t}\n\tif r.ResId != \"\" {\n\t\tif r.Command != \"\" {\n\t\t\treturn fmt.Errorf(\"response packets may not have command set\")\n\t\t}\n\t\tif r.ReqId == \"\" {\n\t\t\treturn fmt.Errorf(\"response packets must have reqid set\")","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshutil/wshrpc.go#L151-L187","documentation":"Packet validation error: COMMAND packets must not set a datatype. Datatype describes response payload encoding and is invalid on an outbound command packet, which is rejected.","triggerScenarios":"Calling Validate on an RpcMessage with Command set and DataType non-empty.","commonSituations":"Copy-paste from response-packet construction code where DataType annotates Data; helpers that stamp DataType unconditionally before sending.","solutions":["Clear DataType and put the payload in Data (marshaled per the command's MappedData type)","Remove any code that pre-sets DataType on outgoing commands","Round-trip a sample command through Validate in tests to catch regression"],"exampleFix":"// before\nmsg := wshutil.RpcMessage{Command: \"controller.sendinput\", DataType: \"inputdata\", Data: b}\n// after\nmsg := wshutil.RpcMessage{Command: \"controller.sendinput\", Data: b}","handlingStrategy":"validation","validationCode":"if msg.Command != \"\" {\n\tmsg.DataType = \"\"\n}\nif err := msg.Validate(); err != nil { return err }","typeGuard":"func commandHasNoDataType(msg wshutil.RpcMessage) bool {\n\treturn msg.Command == \"\" || msg.DataType == \"\"\n}","tryCatchPattern":"if err := msg.Validate(); err != nil {\n\treturn fmt.Errorf(\"command has datatype: %w\", err)\n}","preventionTips":["Set Data only, never DataType, on command packets","Don't copy response-construction code into command senders","Add a regression test validating every command type the app sends"],"tags":["wsh","rpc","validation","serialization"],"backgroundTag":"invalid-rpc-packet","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}