xtekky/gpt4free · error

download failed: %w

Error message

download failed: %w

What it means

downloadRuntime in g4f-go/download.go wraps the raw http.Client.Get error as 'download failed: %w'. The client is created with no timeout (progress is the feedback mechanism), so this fires on connection-level failures: DNS resolution, refused connections, TLS handshake errors — anything before a response is received.

Source

Thrown at g4f-go/download.go:113

		fmt.Printf("runtime: cached download incomplete, re-downloading\n")
	}

	fmt.Printf("runtime: downloading CPython %s (%s)\n", "3.14.7", humanBytes(spec.Size))
	fmt.Printf("  %s\n", spec.URL)
	start := time.Now()

	out, err := os.Create(partName(binDir))
	if err != nil {
		return err
	}
	// Network http.Client with no default timeout: progress is what keeps the
	// user informed, not a hard cutoff.
	client := &http.Client{}
	resp, err := client.Get(spec.URL)
	if err != nil {
		out.Close()
		os.Remove(partName(binDir))
		return fmt.Errorf("download failed: %w", err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		out.Close()
		os.Remove(partName(binDir))
		return fmt.Errorf("download failed: HTTP %s", resp.Status)
	}

	// Prefer Content-Length; fall back to manifest size.
	total := resp.ContentLength
	if total <= 0 {
		total = spec.Size
	}
	_, copyErr := copyWithProgress(out, resp.Body, total, start)
	if cerr := out.Close(); copyErr == nil {
		copyErr = cerr
	}
	if copyErr != nil {

View on GitHub (pinned to 973504e177)

Solutions

  1. Check connectivity to the runtime URL (curl -I <spec.URL>) and fix DNS/proxy/firewall issues
  2. If behind a TLS-intercepting proxy, install its CA into the system trust store or set SSL_CERT_FILE
  3. Inspect the wrapped error (%w) with errors.Unwrap / %v to see whether it is dial, DNS, or TLS
  4. Retry — transient network failures are common for large runtime downloads

Example fix

# before
g4f  # runtime: download failed: dial tcp: lookup cdn.example: no such host

# after
# fix DNS or proxy, or point to a reachable mirror in runtime.json
curl -I https://your-runtime-host/runtime.tar.gz  # verify reachability
Defensive patterns

Strategy: retry

Validate before calling

if _, err := net.LookupHost(urlHost(spec.URL)); err != nil {
    // DNS broken: fail fast with a clear message before downloading
}

Try / catch

err := downloadRuntime(binDir, cachePath, spec)
if err != nil {
    if var ne net.Error; errors.As(err, &ne) || strings.Contains(err.Error(), "download failed") {
        // exponential backoff retry, then surface the unwrapped cause
    }
    return err
}

Prevention

When it happens

Trigger: client.Get(spec.URL) failing: no internet, DNS for the runtime host broken, TLS certificate verification failure, firewall/proxy blocking the runtime CDN, or the URL scheme being invalid.

Common situations: Offline machines; corporate TLS-intercepting proxies without the CA in the system pool; IPv6-broken networks causing dial timeouts; mistyped URL in a locally modified runtime.json.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/04bc361d91702a14. Report an issue: GitHub.