alibaba/open-code-review · error

Base URL %q must include a host

Error message

Base URL %q must include a host

What it means

validateBaseURL requires a non-empty Host component; a URL like "https://" or "https:///path" parses fine but names no server, so it is rejected with this message. This prevents saving a Base URL that would produce requests with no destination.

Source

Thrown at cmd/opencodereview/provider_cmd.go:459

	if len(key) <= 8 {
		return "***"
	}
	return key[:4] + "***" + key[len(key)-4:]
}

// validateBaseURL checks that a provider Base URL has an http or https scheme
// and a non-empty host, giving the user immediate feedback rather than
// a runtime failure when the LLM client tries to use it.
func validateBaseURL(raw string) error {
	parsed, err := url.Parse(raw)
	if err != nil {
		return fmt.Errorf("invalid Base URL %q: %w", raw, err)
	}
	if parsed.Scheme != "http" && parsed.Scheme != "https" {
		return fmt.Errorf("Base URL must use http or https scheme, got %q", parsed.Scheme)
	}
	if parsed.Host == "" {
		return fmt.Errorf("Base URL %q must include a host", raw)
	}
	return nil
}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Include the full host in the Base URL, e.g. https://api.example.com/v1
  2. Re-check the vendor's documented endpoint and paste it completely
  3. Ensure any templated host variable is actually populated before running the set command

Example fix

// before
$ ocr config provider set base-url "https:///v1"
// error: Base URL "https:///v1" must include a host
// after
$ ocr config provider set base-url "https://api.example.com/v1"
Defensive patterns

Strategy: validation

Validate before calling

u, _ := url.Parse(raw)
if u != nil && u.Host == "" {
    return fmt.Errorf("Base URL %q needs a host, e.g. https://api.example.com", raw)
}

Type guard

func hasURLHost(raw string) bool {
    u, err := url.Parse(raw)
    return err == nil && u.Host != ""
}

Try / catch

if err := applyProviderField(...); err != nil {
    if strings.Contains(err.Error(), "must include a host") {
        fmt.Fprintf(os.Stderr, "hostname missing — paste the full endpoint URL\n")
    }
    return err
}

Prevention

When it happens

Trigger: applyProviderField receiving a Base URL with a scheme but no host — e.g. "https://", "http:///v1", or a value reduced to only a path after bad editing.

Common situations: Truncated paste that lost the hostname; accidentally deleting the host while editing the path portion; templating where the host variable was empty.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/8f8a9ff7e9fd911b. Report an issue: GitHub.