wavetermdev/waveterm · error
file type requires mimetype
Error message
file type requires mimetype
What it means
Validation error: a file-type message part is missing the required mimetype field.
Source
Thrown at pkg/aiusechat/uctypes/uctypes.go:415
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")
}
// If URL is set, validate it's https or data URL
if hasURL {
parsedURL, err := url.Parse(p.URL)
if err != nil {View on GitHub (pinned to a4447c1563)
Solutions
- Set MimeType explicitly, e.g. "image/png" or "application/pdf"
- Detect the type with http.DetectContentType(data) before building the part
- Fix the client JSON to include the "mimetype" field
Example fix
// before
part := uctypes.AIMessagePart{Type: "file", Data: data}
// after
part := uctypes.AIMessagePart{Type: "file", MimeType: http.DetectContentType(data), Data: data} Defensive patterns
Strategy: validation
Validate before calling
func hasMimeType(p uctypes.AIMessagePart) bool {
return p.Type == uctypes.AIMessagePartTypeFile && p.MimeType != ""
}
// mime := http.DetectContentType(data) when unknown Type guard
func asTypedFilePart(p uctypes.AIMessagePart) (mime string, ok bool) {
if p.Type == uctypes.AIMessagePartTypeFile && p.MimeType != "" {
return p.MimeType, true
}
return "", false
} Prevention
- Sniff MIME with http.DetectContentType when the type is unknown
- Include the "mimetype" key in client JSON payloads
- Never build a file part literal without MimeType
When it happens
Trigger: AIMessagePart{Type:"file", Data: data} or {Type:"file", URL: ...} with MimeType left empty, then Validate() is called (directly or via AIMessage.Validate on a POSTed message).
Common situations: Constructing a file part from raw bytes without sniffing the content type; JSON payloads omitting the "mimetype" key; inferring MIME from extension and getting empty string for extensionless files.
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
- file type requires either data or url
- file type cannot have both data and url set
- text type requires non-empty text field
- text type cannot have file fields set
- file type cannot have text field set
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/62e98ebe7bdffa15.
Report an issue: GitHub.