wavetermdev/waveterm · error

file type cannot have text field set

Error message

file type cannot have text field set

What it means

Validation error: a message part of file type must not carry a text field; text and file payloads are mutually exclusive.

Source

Thrown at pkg/aiusechat/uctypes/uctypes.go:411

	return nil
}

func (p *AIMessagePart) Validate() error {
	if p.Type == AIMessagePartTypeText {
		if p.Text == "" {
			return fmt.Errorf("text type requires non-empty text field")
		}
		// Check that no file fields are set
		if p.FileName != "" || p.MimeType != "" || len(p.Data) > 0 || p.URL != "" {
			return fmt.Errorf("text type cannot have file fields set")
		}
		return nil
	}

	if p.Type == AIMessagePartTypeFile {
		if p.Text != "" {
			return fmt.Errorf("file type cannot have text field set")
		}

		if p.MimeType == "" {
			return fmt.Errorf("file type requires mimetype")
		}

		// Either data or url (not both) must be set
		hasData := len(p.Data) > 0
		hasURL := p.URL != ""

		if !hasData && !hasURL {
			return fmt.Errorf("file type requires either data or url")
		}

		if hasData && hasURL {
			return fmt.Errorf("file type cannot have both data and url set")
		}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Set Text to "" on the file part
  2. Emit a separate {"type":"text"} part for the caption ahead of the file part

Example fix

// before
part := uctypes.AIMessagePart{Type: "file", Text: "my screenshot", MimeType: "image/png", Data: data}
// after
parts := []uctypes.AIMessagePart{
	{Type: "text", Text: "my screenshot"},
	{Type: "file", MimeType: "image/png", Data: data},
}
Defensive patterns

Strategy: validation

Validate before calling

func validFilePartNoText(p uctypes.AIMessagePart) bool {
	return p.Type == uctypes.AIMessagePartTypeFile && p.Text == ""
}

Type guard

func asFilePart(p uctypes.AIMessagePart) (*uctypes.AIMessagePart, bool) {
	if p.Type == uctypes.AIMessagePartTypeFile && p.Text == "" {
		return &p, true
	}
	return nil, false
}

Prevention

When it happens

Trigger: Building AIMessagePart{Type:"file", Text:"caption", MimeType:..., Data:...} and calling Validate(). Common when a single struct is used to hold both a caption and the attachment.

Common situations: Client UIs that allow a caption with an upload; migration code from formats where a message had text+file in one object (e.g. some chat APIs); copy-paste of a text part with Type changed to "file" but Text left set.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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