wavetermdev/waveterm · error

file type requires either data or url

Error message

file type requires either data or url

What it means

Validation error: a file-type message part has neither inline data nor a URL; exactly one is required.

Source

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

		}
		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 {
				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

View on GitHub (pinned to a4447c1563)

Solutions

  1. Attach the content: set Data to the file bytes (base64 on the wire)
  2. Or set URL to an https:// or data: URL for the file
  3. Fix the upload/read step so Data or URL is actually populated before validation

Example fix

// before
part := uctypes.AIMessagePart{Type: "file", MimeType: "image/png", FileName: "a.png"}
// after
data, err := os.ReadFile("a.png")
part := uctypes.AIMessagePart{Type: "file", MimeType: "image/png", FileName: "a.png", Data: data}
Defensive patterns

Strategy: validation

Validate before calling

func hasAttachmentContent(p uctypes.AIMessagePart) bool {
	return p.Type == uctypes.AIMessagePartTypeFile && (len(p.Data) > 0 || p.URL != "")
}

Type guard

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

Prevention

When it happens

Trigger: AIMessagePart{Type:"file", MimeType:"image/png"} with empty Data and empty URL passed to Validate(). Happens when the upload step failed or the URL assignment was skipped.

Common situations: Asynchronous upload pipeline where the fetch/populate step was skipped; JSON where "data" is base64 empty string and no "url"; conditional code paths that set Data XOR URL but neither branch ran.

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