{"record":{"id":"39e35f876399fb80","repo":"xtekky/gpt4free","slug":"extract-runtime-w","errorCode":null,"errorMessage":"extract runtime: %w","messagePattern":"extract runtime: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"g4f-go/download.go","lineNumber":435,"sourceCode":"\t\treturn \"\", err\n\t}\n\tspec, err := runtimeSpecForHost(manifest)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tcachePath := filepath.Join(binDir, \".g4f-runtime\", \"runtime-\"+filepath.Base(spec.URL))\n\tif err := downloadRuntime(binDir, cachePath, spec); err != nil {\n\t\treturn \"\", err\n\t}\n\n\t// Extract unless already done (stamp written after successful extract).\n\tokStamp := installedOkName(binDir)\n\tif _, err := os.Stat(okStamp); err != nil {\n\t\tfmt.Println(\"runtime: extracting (this can take a minute)...\")\n\t\tstart := time.Now()\n\t\tif err := extractRuntime(binDir, cachePath); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"extract runtime: %w\", err)\n\t\t}\n\t\tif err := os.WriteFile(okStamp, []byte(\"ok\"), 0o644); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tfmt.Printf(\"runtime: extracted in %s\\n\", time.Since(start).Round(time.Second))\n\t}\n\n\treturn finalizeRuntime(binDir)\n}\n\n// Check if a command/binary exists in PATH\nfunc commandExists(cmd string) bool {\n\t_, err := exec.LookPath(cmd)\n\treturn err == nil\n}\n\n// finalizeRuntime does platform-specific finishing (launcher setup) and\n// returns the interpreter path.","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f-go/download.go#L417-L453","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Unwrap the %w cause: fs errors point to permissions/disk, tar/gzip errors to a corrupt archive","Free disk space (the extracted Python runtime is much larger than the archive) and ensure write access to binDir","Delete the ok-stamp and cached archive, then retry a clean download+extract","If the archive is corrupt, re-download from the official URL and confirm the sha256 pin"],"exampleFix":"# before\n# extract runtime: gzip: invalid header\n\n# after\nrm -rf .g4f-runtime                 # clear partial extraction + stamp\ndf -h .                             # confirm disk space\ng4f                                  # fresh download + extract","handlingStrategy":"try-catch","validationCode":"// fail fast when extraction cannot possibly fit\nif free := diskFree(binDir); free < uint64(spec.Size)*3 {\n    return fmt.Errorf(\"insufficient disk: need ~%d, have %d\", spec.Size*3, free)\n}","typeGuard":null,"tryCatchPattern":"exe, err := ensureRuntime(binDir)\nif err != nil && strings.Contains(err.Error(), \"extract runtime\") {\n    // inspect errors.Unwrap: clean .g4f-runtime, fix disk/permissions, retry\n}","preventionTips":["Provision disk for several times the runtime archive size","Verify write permissions on binDir before first run","Clear the .g4f-runtime directory when a bootstrap fails mid-way"],"tags":["go","extraction","disk-full","permissions","runtime-bootstrap"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}