wavetermdev/waveterm · error

command packets may not have error set

Error message

command packets may not have error set

What it means

Packet validation error: COMMAND packets must not carry an error. Errors are only meaningful on response packets; a command with error set is malformed and rejected.

Source

Thrown at pkg/wshutil/wshrpc.go:166

	}
	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")
		}
		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")

View on GitHub (pinned to a4447c1563)

Solutions

  1. Send a response packet with ResId and Error set instead of attaching Error to the command
  2. Clear Error when sending the command
  3. Use the Rpc error-return path in the handler signature rather than hand-building error messages

Example fix

// before
msg := wshutil.RpcMessage{Command: "job.start", Error: "no space"}
// after
resp := wshutil.RpcMessage{ResId: reqId, Error: "no space"}
Defensive patterns

Strategy: validation

Validate before calling

if msg.Command != "" && msg.Error != "" {
	return fmt.Errorf("send errors on response packets, not commands")
}
if err := msg.Validate(); err != nil { return err }

Type guard

func isCleanCommand(msg wshutil.RpcMessage) bool {
	return msg.Command == "" || (msg.Error == "" && msg.ResId == "" && msg.DataType == "")
}

Try / catch

if err := msg.Validate(); err != nil {
	return fmt.Errorf("command has error field: %w", err)
}

Prevention

When it happens

Trigger: Calling Validate on an RpcMessage with Command set and Error non-empty.

Common situations: A handler that tries to return an error by mutating the request message instead of sending a response; error-propagation helpers that set both Command and Error on one struct.

Related errors


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