xtekky/gpt4free · error

extract runtime: %w

Error message

extract runtime: %w

What it means

ensureRuntime (g4f-go/download.go) wraps any failure of extractRuntime as 'extract runtime: %w'. The archive downloaded and verified fine, but turning it into an extracted tree failed: tar/gzip format errors, disk full, permission errors creating files under binDir, or the unsafe-path guards (412/413) firing.

Source

Thrown at g4f-go/download.go:435

		return "", err
	}
	spec, err := runtimeSpecForHost(manifest)
	if err != nil {
		return "", err
	}

	cachePath := filepath.Join(binDir, ".g4f-runtime", "runtime-"+filepath.Base(spec.URL))
	if err := downloadRuntime(binDir, cachePath, spec); err != nil {
		return "", err
	}

	// Extract unless already done (stamp written after successful extract).
	okStamp := installedOkName(binDir)
	if _, err := os.Stat(okStamp); err != nil {
		fmt.Println("runtime: extracting (this can take a minute)...")
		start := time.Now()
		if err := extractRuntime(binDir, cachePath); err != nil {
			return "", fmt.Errorf("extract runtime: %w", err)
		}
		if err := os.WriteFile(okStamp, []byte("ok"), 0o644); err != nil {
			return "", err
		}
		fmt.Printf("runtime: extracted in %s\n", time.Since(start).Round(time.Second))
	}

	return finalizeRuntime(binDir)
}

// Check if a command/binary exists in PATH
func commandExists(cmd string) bool {
	_, err := exec.LookPath(cmd)
	return err == nil
}

// finalizeRuntime does platform-specific finishing (launcher setup) and
// returns the interpreter path.

View on GitHub (pinned to 973504e177)

Solutions

  1. Unwrap the %w cause: fs errors point to permissions/disk, tar/gzip errors to a corrupt archive
  2. Free disk space (the extracted Python runtime is much larger than the archive) and ensure write access to binDir
  3. Delete the ok-stamp and cached archive, then retry a clean download+extract
  4. If the archive is corrupt, re-download from the official URL and confirm the sha256 pin

Example fix

# before
# extract runtime: gzip: invalid header

# after
rm -rf .g4f-runtime                 # clear partial extraction + stamp
df -h .                             # confirm disk space
g4f                                  # fresh download + extract
Defensive patterns

Strategy: try-catch

Validate before calling

// fail fast when extraction cannot possibly fit
if free := diskFree(binDir); free < uint64(spec.Size)*3 {
    return fmt.Errorf("insufficient disk: need ~%d, have %d", spec.Size*3, free)
}

Try / catch

exe, err := ensureRuntime(binDir)
if err != nil && strings.Contains(err.Error(), "extract runtime") {
    // inspect errors.Unwrap: clean .g4f-runtime, fix disk/permissions, retry
}

Prevention

When it happens

Trigger: Calling the g4f-go runtime bootstrap when extraction fails: os.MkdirAll/OpenFile errors under dest, gzip.NewReader invalid header, tar truncated mid-stream, or traversal guards aborting.

Common situations: Disk-full during the multi-minute extraction of the large Python runtime; read-only or permission-restricted install dir; partially written archives that passed size but fail gzip framing; the ok-stamp (.runtime-ok) directory not writable.

Related errors


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