{"record":{"id":"0346e3c08a0922e7","repo":"jeessy2/ddns-go","slug":"failed-to-decompress","errorCode":null,"errorMessage":"failed to decompress","messagePattern":"failed to decompress","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/update/errors.go","lineNumber":8,"sourceCode":"// Based on https://github.com/creativeprojects/go-selfupdate/blob/v1.1.1/errors.go\n\npackage update\n\nimport \"errors\"\n\nvar (\n\terrCannotDecompressFile        = errors.New(\"failed to decompress\")\n\terrExecutableNotFoundInArchive = errors.New(\"executable not found\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":11,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/util/update/errors.go#L1-L11","documentation":"errCannotDecompressFile (\"failed to decompress\") is the sentinel error for the auto-update archive reading path. unzip wraps any failure while reading the zip source or constructing zip.NewReader with %w zip 文件: ...; untar does the same for tar.gz. Callers can match it with errors.Is to report 'could not decompress the update package'.","triggerScenarios":"Calling unzip when the downloaded file is truncated/corrupt (io.ReadAll or zip.NewReader fails), or untar when the .tar.gz stream is corrupt or not gzip/tar formatted.","commonSituations":"Interrupted download leaves a partial archive; CDN/proxy returns an HTML error page saved as the update file; disk full during download; wrong URL serving a non-archive payload.","solutions":["Re-download the update package and verify its checksum/size before unzipping","Check disk space and that the file was fully written (io.ReadAll error often means read/stream failure)","Confirm the update URL actually serves the expected zip/tar.gz (not an HTML error page)","Use errors.Is(err, update.errCannotDecompressFile) to branch handling and prompt a retry"],"exampleFix":"// before\nbuf, err := os.ReadFile(dlPath)\n// use buf directly\n// after\nbuf, err := os.ReadFile(dlPath)\nsum := sha256.Sum256(buf)\nif !bytes.Equal(sum[:], expectedSum) {\n  return fmt.Errorf(\"%w: checksum mismatch, re-download\", update.ErrCannotDecompress)\n}","handlingStrategy":"validation","validationCode":"// verify the archive before decompressing\nfi, err := os.Stat(updateFile)\nif err != nil || fi.Size() == 0 {\n  return errors.New(\"update archive missing or empty\")\n}\nsum := sha256.Sum256(buf)\nif !bytes.Equal(sum[:], expectedChecksum) {\n  return errors.New(\"update archive checksum mismatch — re-download\")\n}","typeGuard":"func isCannotDecompress(err error) bool {\n  return errors.Is(err, update.errCannotDecompressFile) // exported wrapper recommended\n}","tryCatchPattern":"archive, err := update.unzip(path, cmd)\nif err != nil {\n  if isCannotDecompress(err) {\n    // delete the corrupt file and re-download before retrying\n    os.Remove(path)\n    return reDownloadAndRetry()\n  }\n  return err\n}","preventionTips":["Verify checksums/signatures of downloaded update packages before extraction","Ensure downloads complete fully (check Content-Length vs actual size)","Confirm the update URL serves the archive, not an HTML error page","Check available disk space before downloading/updating"],"tags":["go","update","archive","corrupt-file"],"backgroundTag":"decompress-failed","analyzedSha":"5874c2e6667c69357ab95079421131104bd3fcae","analyzedAt":"2026-09-03T15:41:16.799Z","contentChangedAt":"2026-09-03T15:41:16.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}