wavetermdev/waveterm · error

cancel packets may not have data set

Error message

cancel packets may not have data set

What it means

Packet validation error: CANCEL packets must not carry a data payload. A cancel only references the request being cancelled (by resid); attaching data is a protocol violation and the packet is rejected.

Source

Thrown at pkg/wshutil/wshrpc.go:157

}

func (r *RpcMessage) IsRpcRequest() bool {
	return r.Command != "" || r.ReqId != ""
}

func (r *RpcMessage) Validate() error {
	if r.ReqId != "" && r.ResId != "" {
		return fmt.Errorf("request packets may not have both reqid and resid set")
	}
	if r.Cancel {
		if r.Command != "" {
			return fmt.Errorf("cancel packets may not have command set")
		}
		if r.ReqId == "" && r.ResId == "" {
			return fmt.Errorf("cancel packets must have reqid or resid set")
		}
		if r.Data != nil {
			return fmt.Errorf("cancel packets may not have data set")
		}
		return nil
	}
	if r.Command != "" {
		if r.ResId != "" {
			return fmt.Errorf("command packets may not have resid set")
		}
		if r.Error != "" {
			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")

View on GitHub (pinned to a4447c1563)

Solutions

  1. Set Data = nil on the cancel message
  2. Build the cancel packet from scratch instead of mutating the original request
  3. Ensure generic encode helpers do not attach Data to control packets

Example fix

// before
msg := wshutil.RpcMessage{Cancel: true, ReqId: origId, Data: payload}
// after
msg := wshutil.RpcMessage{Cancel: true, ReqId: origId, Data: nil}
Defensive patterns

Strategy: validation

Validate before calling

if msg.Cancel {
	msg.Data = nil
}
if err := msg.Validate(); err != nil { return err }

Type guard

func cancelHasNoData(msg wshutil.RpcMessage) bool {
	return !msg.Cancel || msg.Data == nil
}

Try / catch

if err := msg.Validate(); err != nil {
	return fmt.Errorf("cancel packet has data: %w", err)
}

Prevention

When it happens

Trigger: Calling Validate on an RpcMessage with Cancel=true, valid ReqId/ResId, and Data != nil.

Common situations: Reusing a request message struct (which had a Data payload) and just setting Cancel=true; serialization pipelines that always populate Data.

Related errors


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