usememos/memos · warning
empty hostname
Error message
empty hostname
What it means
validateURL successfully parsed the URL but u.Hostname() returned an empty string, meaning there is no host to resolve or connect to. Typical inputs are scheme-only strings or URLs whose authority section is empty.
Source
Thrown at internal/httpgetter/html_meta.go:120
}
func isInternalIP(ip net.IP) bool {
return ip.IsLoopback() || ip.IsPrivate() || ip.IsLinkLocalUnicast() || ip.IsUnspecified()
}
func validateURL(urlStr string) error {
u, err := url.Parse(urlStr)
if err != nil {
return errors.New("invalid URL format")
}
if u.Scheme != "http" && u.Scheme != "https" {
return errors.New("only http/https protocols are allowed")
}
host := u.Hostname()
if host == "" {
return errors.New("empty hostname")
}
if ip := net.ParseIP(host); ip != nil && isInternalIP(ip) {
return errors.Wrap(ErrInternalIP, ip.String())
}
return nil
}
type HTMLMeta struct {
Title string `json:"title"`
Description string `json:"description"`
Image string `json:"image"`
}
func GetHTMLMeta(urlStr string) (*HTMLMeta, error) {
if err := validateURL(urlStr); err != nil {
return nil, errView on GitHub (pinned to 14d757ce1f)
Solutions
- Fix the URL to include a hostname: `https://example.com/path`
- Check client-side URL construction (base join logic) for dropped hosts
- Validate with a URL parser requiring a non-empty host before submitting
Example fix
// before
GetHTMLMeta("https:///notes/1")
// after
GetHTMLMeta("https://example.com/notes/1") Defensive patterns
Strategy: validation
Validate before calling
func hasHost(raw string) bool {
u, err := url.Parse(strings.TrimSpace(raw))
return err == nil && u.Hostname() != ""
} Try / catch
// Map to a friendly client error
if err := fetchPreview(raw); err != nil && strings.Contains(err.Error(), "empty hostname") {
return errors.New("URL is missing its host: include the domain name")
} Prevention
- Build URLs via url.URL{Scheme, Host, Path} instead of string concatenation
- Assert non-empty host before network calls
- Test URL construction helpers with table-driven cases
When it happens
Trigger: URLs like `https:///path` (empty authority), `http://?q=1`, or `https:` alone. Also some relative or malformed inputs that parse but carry no host.
Common situations: Programmatic URL construction that concatenates a base and path incorrectly and drops the host; user typos like `https:// /page`; frontends sending the path component only.
Related errors
- invalid URL format
- only http/https protocols are allowed
- SMTP host is required
- SMTP port must be between 1 and 65535
- from email is required
AI-assisted analysis of usememos/memos@14d757ce1f (2026-08-15).
Data as JSON: /api/errors/fb6d80848f00c4d5.
Report an issue: GitHub.