{"record":{"id":"f129fbf9262656c1","repo":"chenhg5/cc-connect","slug":"tar-w","errorCode":null,"errorMessage":"tar: %w","messagePattern":"tar: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/update.go","lineNumber":335,"sourceCode":"\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer f.Close()\n\n\tgz, err := gzip.NewReader(f)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"gzip: %w\", err)\n\t}\n\tdefer gz.Close()\n\n\ttr := tar.NewReader(gz)\n\tfor {\n\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}","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/update.go#L317-L353","documentation":"extractFromTarGz wraps errors from tar.Reader.Next() as \"tar: %w\". The gzip stream opened fine, but reading the tar entries inside it failed partway — the tar payload is corrupt or malformed after the header region.","triggerScenarios":"tr.Next() returns a non-EOF error while iterating entries: truncated download (valid gzip header, cut-off tar), bit corruption, an asset that is gzip but not tar, or an I/O read error from disk while streaming.","commonSituations":"Flaky network truncated the download mid-archive; manually edited or re-compressed archive; CDN/cache serving a corrupted asset; filesystem read errors on the temp file.","solutions":["Re-download the archive (delete any cached copy) and retry — truncation is the most common cause","Verify the archive integrity locally: `gzip -t file.tar.gz && tar -tf file.tar.gz`","Compare the asset checksum with the value published in the release notes","If persistent, inspect the release asset itself — it may be corrupted upstream"],"exampleFix":"// before\nif err != nil {\n    return \"\", fmt.Errorf(\"tar: %w\", err)\n}\n// after\nif err != nil {\n    return \"\", fmt.Errorf(\"tar: %w (archive truncated or corrupt; re-download)\", err)\n}","handlingStrategy":"validation","validationCode":"// test archive integrity before extraction:\ncmd := exec.Command(\"sh\", \"-c\", fmt.Sprintf(\"gzip -t %s && tar -tzf %s >/dev/null\", path, path))\nif err := cmd.Run(); err != nil {\n    return errors.New(\"archive failed integrity check; re-download\")\n}","typeGuard":null,"tryCatchPattern":"// Go: treat mid-stream tar errors as corrupt-download\nif _, err := extractFromTarGz(path); err != nil {\n    if strings.Contains(err.Error(), \"tar:\") {\n        os.Remove(path)\n        return errors.New(\"archive corrupt mid-stream; deleted and re-download required\")\n    }\n    return err\n}","preventionTips":["Compare downloaded bytes with the Content-Length before extracting","Prefer checksums published with the release over size checks alone","Don't hand-edit or recompress release archives","Investigate CDN/cache layers serving corrupted copies if it recurs across hosts"],"tags":["archive","tar","corrupt-file","update-checker","download"],"backgroundTag":"file-read-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}