{"record":{"id":"cc06a7a15dfc56ce","repo":"chenhg5/cc-connect","slug":"extract-w","errorCode":null,"errorMessage":"extract: %w","messagePattern":"extract: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/update.go","lineNumber":348,"sourceCode":"\t\thdr, err := tr.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"tar: %w\", err)\n\t\t}\n\t\tif hdr.Typeflag != tar.TypeReg {\n\t\t\tcontinue\n\t\t}\n\t\tif strings.HasPrefix(hdr.Name, \"cc-connect\") {\n\t\t\ttmp, err := os.CreateTemp(\"\", \"cc-connect-update-*\")\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\tif _, err := io.Copy(tmp, tr); err != nil {\n\t\t\t\ttmp.Close()\n\t\t\t\tos.Remove(tmp.Name())\n\t\t\t\treturn \"\", fmt.Errorf(\"extract: %w\", err)\n\t\t\t}\n\t\t\ttmp.Close()\n\t\t\treturn tmp.Name(), nil\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"binary not found in archive\")\n}\n\nfunc extractFromZip(archivePath string) (string, error) {\n\tr, err := zip.OpenReader(archivePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"zip: %w\", err)\n\t}\n\tdefer r.Close()\n\n\tfor _, f := range r.File {\n\t\tif !strings.HasPrefix(f.Name, \"cc-connect\") {\n\t\t\tcontinue","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/update.go#L330-L366","documentation":"extractFromTarGz wraps errors from io.Copy(tmp, tr) as \"extract: %w\". The tar entry named cc-connect* was found and a temp file created, but streaming its contents into the temp file failed — either a decompression error mid-stream or a disk write error.","triggerScenarios":"io.Copy(tmp, tr) errors: disk full on the temp volume, write permission failure in os.TempDir(), or the gzip/tar stream corrupting mid-file (surfaces as a read error during the copy).","commonSituations":"Full or nearly-full disk (common in constrained CI containers); read-only or noexec /tmp; disk quota exceeded; archive corrupted partway through the binary entry.","solutions":["Check free disk space on the temp filesystem (df -h /tmp) and clean up","Check /tmp permissions and mount flags (read-only, noexec, quota) and set TMPDIR to a writable location if needed","Retry after fixing storage — if it recurs with plenty of space, the archive is likely corrupt; re-download","Verify the extracted binary with a checksum comparison before swapping it in"],"exampleFix":"// before\nif _, err := io.Copy(tmp, tr); err != nil {\n    tmp.Close()\n    os.Remove(tmp.Name())\n    return \"\", fmt.Errorf(\"extract: %w\", err)\n}\n// after\nif _, err := io.Copy(tmp, tr); err != nil {\n    tmp.Close()\n    os.Remove(tmp.Name())\n    return \"\", fmt.Errorf(\"extract: %w (check disk space on %s)\", err, os.TempDir())\n}","handlingStrategy":"fallback","validationCode":"// ensure the temp volume can hold the archive before extracting:\nvar st syscall.Statfs_t\nsyscall.Statfs(os.TempDir(), &st)\nfree := int64(st.Bavail) * int64(st.Bsize)\ninfo, _ := os.Stat(archivePath)\nif free < info.Size()*3 { return errors.New(\"insufficient temp disk space for extraction\") }","typeGuard":null,"tryCatchPattern":"// Go: fall back to an alternate temp dir when extraction fails\nout, err := extractFromTarGz(path)\nif err != nil {\n    if strings.Contains(err.Error(), \"extract:\") {\n        os.Setenv(\"TMPDIR\", \"/var/tmp\") // alternate writable location\n        out, err = extractFromTarGz(path)\n    }\n    if err != nil { return err }\n}","preventionTips":["Monitor free space on /tmp (or TMPDIR) on hosts that self-update","Set TMPDIR to a volume with adequate space in constrained containers","Verify written files with checksums before replacing the live binary","Clean up stale cc-connect-update-* temp files from failed updates"],"tags":["archive","filesystem","disk-space","update-checker","io"],"backgroundTag":"file-write-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}