GopeedLab/gopeed · error

invalid request url

Error message

invalid request url

What it means

base.Request.Validate() (pkg/base/model.go:44) enforces the single invariant that a request must carry a URL. The URL is the key the whole fetch pipeline (resolve, proxying, fetcher selection) keys off, so an empty value is rejected up front rather than failing later inside a protocol adapter.

Source

Thrown at pkg/base/model.go:48

	r.Labels = labels
}

// PutLabel sets a label on the request.
func (r *Request) PutLabel(key, value string) {
	if r.Labels == nil {
		r.Labels = make(map[string]string)
	}
	r.Labels[key] = value
}

// DelLabel deletes a label from the request.
func (r *Request) DelLabel(key string) {
	delete(r.Labels, key)
}

func (r *Request) Validate() error {
	if r.URL == "" {
		return fmt.Errorf("invalid request url")
	}
	return nil
}

type RequestProxyMode string

const (
	// RequestProxyModeFollow follow setting proxy
	RequestProxyModeFollow RequestProxyMode = "follow"
	// RequestProxyModeNone not use proxy
	RequestProxyModeNone RequestProxyMode = "none"
	// RequestProxyModeCustom custom proxy
	RequestProxyModeCustom RequestProxyMode = "custom"
)

type RequestProxy struct {
	Mode   RequestProxyMode `json:"mode"`
	Scheme string           `json:"scheme"`

View on GitHub (pinned to 7b7327ffb3)

Solutions

  1. Set a non-empty URL before calling Validate or submitting the request
  2. Validate upstream input (trim + reject empty) so the error never reaches the library
  3. When decoding from JSON, require the url key (disallow unknown/missing fields) to fail at the boundary

Example fix

// before
req := &base.Request{}
err := req.Validate() // "invalid request url"

// after
req := &base.Request{URL: "https://example.com/file.zip"}
err := req.Validate()
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

req := &base.Request{URL: strings.TrimSpace(input)}
if err := req.Validate(); err != nil {
    if strings.Contains(err.Error(), "invalid request url") {
        return fmt.Errorf("a non-empty request URL is required: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Constructing base.Request{} and forgetting URL; deriving the URL from user input or config that trimmed to empty; copying a struct and clearing the field; JSON-decoding a payload where the url key was absent.

Common situations: CLI/web handlers that pass through empty form fields; config migrations renaming the field so deserialization leaves it zero; tests that build minimal requests and skip URL.

Related errors


AI-assisted analysis of GopeedLab/gopeed@7b7327ffb3 (2026-08-16). Data as JSON: /api/errors/32fca3f585506e46. Report an issue: GitHub.