wavetermdev/waveterm · error

response packets may not have command set

Error message

response packets may not have command set

What it means

Validate() in pkg/wshutil/wshrpc.go checks that each RpcMessage conforms to the packet protocol. A response packet is identified by having ResId set; responses are only acknowledgments/data for a prior request, so they must never carry a Command. This error means a packet marked as a response was built with a command field filled in.

Source

Thrown at pkg/wshutil/wshrpc.go:184

			return fmt.Errorf("command packets may not have error set")
		}
		if r.DataType != "" {
			return fmt.Errorf("command packets may not have datatype set")
		}
		return nil
	}
	if r.ReqId != "" {
		if r.ResId == "" {
			return fmt.Errorf("request packets must have resid set")
		}
		if r.Timeout != 0 {
			return fmt.Errorf("non-command request packets may not have timeout set")
		}
		return nil
	}
	if r.ResId != "" {
		if r.Command != "" {
			return fmt.Errorf("response packets may not have command set")
		}
		if r.ReqId == "" {
			return fmt.Errorf("response packets must have reqid set")
		}
		if r.Timeout != 0 {
			return fmt.Errorf("response packets may not have timeout set")
		}
		return nil
	}
	return fmt.Errorf("invalid packet: must have command, reqid, or resid set")
}

type rpcData struct {
	Command string
	Route   string
	ResCh   chan *RpcMessage
	Handler *RpcRequestHandler
}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Remove the Command field from the response packet; keep only ResId, ReqId, and the response data.
  2. If you intended to send a new command, clear ResId instead and set Command/ReqId as a request packet.
  3. Use SendResponse/SendResponseError on RpcResponseHandler rather than hand-building response RpcMessages.
  4. Run Validate() on locally built packets in tests to catch malformed shapes early.

Example fix

// before
msg := wshrpc.RpcMessage{Command: "waveclient:get", ResId: "res-1", ReqId: "req-1"}
// after
msg := wshrpc.RpcMessage{ResId: "res-1", ReqId: "req-1"}
Defensive patterns

Strategy: validation

Validate before calling

func validRes(m wshrpc.RpcMessage) error {
    if m.ResId != "" && m.Command != "" {
        return fmt.Errorf("response packet has command set: %v", m.Command)
    }
    return nil
}

Type guard

func isPureResponse(m wshrpc.RpcMessage) bool {
    return m.ResId != "" && m.Command == ""
}

Prevention

When it happens

Trigger: Manually constructing or marshaling an RpcMessage with both ResId and Command set, or replying via a response path while accidentally copying the original request's Command field into the reply.

Common situations: Custom RPC client code that echoes request fields into responses; version drift where one side serializes packets with command carried over; hand-written test fixtures for WSH RPC messages.

Related errors


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