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
- Set Text to "" on the file part
- 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
- Keep captions in separate text parts
- Zero out the Text field when repurposing a part struct
- Run Validate() on every part before sending
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
- text type requires non-empty text field
- text type cannot have file fields set
- file type requires mimetype
- file type requires either data or url
- file type cannot have both data and url set
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/f6382193c715df41.
Report an issue: GitHub.