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, err

View on GitHub (pinned to 14d757ce1f)

Solutions

  1. Fix the URL to include a hostname: `https://example.com/path`
  2. Check client-side URL construction (base join logic) for dropped hosts
  3. 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

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


AI-assisted analysis of usememos/memos@14d757ce1f (2026-08-15). Data as JSON: /api/errors/fb6d80848f00c4d5. Report an issue: GitHub.