wavetermdev/waveterm · error
invalid url: %w
Error message
invalid url: %w
What it means
Wrapped validation error: the URL on a file-type part failed url.Parse-based validation. Wraps the parse error.
Source
Thrown at pkg/aiusechat/uctypes/uctypes.go:434
}
// 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)
}
// ---------------------
// AI SDK Streaming Protocol
// Type can be one of these consts...
// text-start, text-delta, text-end,
// reasoning-start, reasoning-delta, reasoning-end,View on GitHub (pinned to a4447c1563)
Solutions
- Fix the URL string so it parses (correct scheme, encoding)
- If the value is a local path, upload/serve it and store a full https:// URL instead
- For inline small files use a data: URL, e.g. data:image/png;base64,...
Example fix
// before
part := uctypes.AIMessagePart{Type: "file", MimeType: "image/png", URL: "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 parseableURL(raw string) bool {
_, err := url.Parse(raw)
return err == nil
} Type guard
func validFileURL(p uctypes.AIMessagePart) (*url.URL, bool) {
if p.Type != uctypes.AIMessagePartTypeFile || p.URL == "" {
return nil, false
}
u, err := url.Parse(p.URL)
if err != nil {
return nil, false
}
return u, true
} Prevention
- url.Parse the string before assigning it to the URL field
- Never store local paths or relative paths in the URL field
- Percent-encode user-supplied URL components with url.PathEscape
When it happens
Trigger: AIMessagePart{Type:"file", MimeType:..., URL: "ht!tp://x"} or other malformed URL (control characters, bad percent-encoding) passed to Validate().
Common situations: User-supplied attachment URLs passed through unvalidated; concatenation bugs producing broken URLs (missing scheme, stray spaces); storing relative paths in the URL field.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- url must be https or data URL, got %q
- unsupported URL protocol in file part: %s
- 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/2dd4a0d5ca2f1843.
Report an issue: GitHub.