AdguardTeam/AdGuardHome · error

constructing request to %s: %w

Error message

constructing request to %s: %w

What it means

Updater.VersionInfo failed at http.NewRequestWithContext for the version-check URL; the URL is included in the message. This is a client-side request construction failure, not a network failure.

Source

Thrown at internal/updater/check.go:54

// VersionInfo downloads the latest version information.  If forceRecheck is
// false and there are cached results, those results are returned.
func (u *Updater) VersionInfo(ctx context.Context, forceRecheck bool) (vi VersionInfo, err error) {
	u.mu.Lock()
	defer u.mu.Unlock()

	now := time.Now()
	recheckTime := u.prevCheckTime.Add(versionCheckPeriod)
	if !forceRecheck && now.Before(recheckTime) {
		u.logger.DebugContext(ctx, "version info recheck is not required yet")

		return u.prevCheckResult, u.prevCheckError
	}

	vcu := u.versionCheckURL
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, vcu, nil)
	if err != nil {
		return VersionInfo{}, fmt.Errorf("constructing request to %s: %w", vcu, err)
	}

	u.logger.DebugContext(ctx, "requesting version data", "url", vcu)

	resp, err := u.client.Do(req)
	if err != nil {
		return VersionInfo{}, fmt.Errorf("sending http request to %s: %w", vcu, err)
	}
	defer func() { err = errors.WithDeferred(err, resp.Body.Close()) }()

	if resp.StatusCode != http.StatusOK {
		return VersionInfo{}, fmt.Errorf(
			"got status code %d, want %d",
			resp.StatusCode,
			http.StatusOK,
		)
	}

View on GitHub (pinned to b41aefbe51)

Solutions

  1. Inspect the URL in the error message and fix the version-check URL configuration
  2. Ensure the URL has a valid scheme and host (https://example.com/version.json)
  3. Reset custom update-server overrides to defaults

Example fix

# before
update_url: "example.com/version.json"
# after
update_url: "https://example.com/version.json"
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(checkURL)
if err != nil || u.Scheme == "" || u.Host == "" { return fmt.Errorf("invalid update URL %q", checkURL) }

Type guard

func validURL(s string) bool { u, err := url.Parse(s); return err == nil && u.IsAbs() && u.Host != "" }

Try / catch

info, err := u.VersionInfo(ctx)
if err != nil { log.Printf("update check failed: %v", err) }

Prevention

When it happens

Trigger: Calling VersionInfo when the configured version check URL is malformed (bad scheme, control characters, unsupported protocol), or the context setup makes request construction fail.

Common situations: Broken/overridden update URL in config (typo, missing scheme), env-var-injected bad URL, or tests with placeholder URLs.

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/8419187bae592dd3. Report an issue: GitHub.