wavetermdev/waveterm · error

file type cannot have both data and url set

Error message

file type cannot have both data and url set

What it means

Validation error: a file-type message part sets both data and URL; they are mutually exclusive.

Source

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

	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 {
				return fmt.Errorf("invalid url: %w", err)
			}

			if parsedURL.Scheme != "https" && parsedURL.Scheme != "data" {
				return fmt.Errorf("url must be https or data URL, got %q", parsedURL.Scheme)
			}
		}
		return nil
	}

	return fmt.Errorf("type must be %q or %q, got %q", AIMessagePartTypeText, AIMessagePartTypeFile, p.Type)
}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Remove the URL field and keep inline Data
  2. Or remove Data and keep only URL (e.g. for large files)
  3. Refactor the part-construction helper so it sets exactly one of Data/URL

Example fix

// before
part := uctypes.AIMessagePart{Type: "file", MimeType: "image/png", Data: data, URL: "https://example.com/a.png"}
// after
part := uctypes.AIMessagePart{Type: "file", MimeType: "image/png", URL: "https://example.com/a.png"}
Defensive patterns

Strategy: validation

Validate before calling

func singleContentSource(p uctypes.AIMessagePart) bool {
	return len(p.Data) == 0 || p.URL == "" // at most one of data/url
}

Type guard

func hasExactlyOneSource(p uctypes.AIMessagePart) bool {
	if p.Type != uctypes.AIMessagePartTypeFile {
		return false
	}
	return (len(p.Data) > 0) != (p.URL != "")
}

Prevention

When it happens

Trigger: AIMessagePart{Type:"file", MimeType:..., Data: data, URL: "https://..."} passed to Validate(); typically when a helper fills in the URL (e.g. a data: preview) while the caller also attached raw bytes.

Common situations: Code that auto-populates URL from uploaded data but keeps Data; merging partial updates where a URL was added to an already-inline attachment; copy-paste building parts from two examples.

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/0f6c03d1db92a7e2. Report an issue: GitHub.