jeessy2/ddns-go · error

failed to decompress

Error message

failed to decompress

What it means

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'.

Source

Thrown at util/update/errors.go:8

// Based on https://github.com/creativeprojects/go-selfupdate/blob/v1.1.1/errors.go

package update

import "errors"

var (
	errCannotDecompressFile        = errors.New("failed to decompress")
	errExecutableNotFoundInArchive = errors.New("executable not found")
)

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Re-download the update package and verify its checksum/size before unzipping
  2. Check disk space and that the file was fully written (io.ReadAll error often means read/stream failure)
  3. Confirm the update URL actually serves the expected zip/tar.gz (not an HTML error page)
  4. Use errors.Is(err, update.errCannotDecompressFile) to branch handling and prompt a retry

Example fix

// before
buf, err := os.ReadFile(dlPath)
// use buf directly
// after
buf, err := os.ReadFile(dlPath)
sum := sha256.Sum256(buf)
if !bytes.Equal(sum[:], expectedSum) {
  return fmt.Errorf("%w: checksum mismatch, re-download", update.ErrCannotDecompress)
}
Defensive patterns

Strategy: validation

Validate before calling

// verify the archive before decompressing
fi, err := os.Stat(updateFile)
if err != nil || fi.Size() == 0 {
  return errors.New("update archive missing or empty")
}
sum := sha256.Sum256(buf)
if !bytes.Equal(sum[:], expectedChecksum) {
  return errors.New("update archive checksum mismatch — re-download")
}

Type guard

func isCannotDecompress(err error) bool {
  return errors.Is(err, update.errCannotDecompressFile) // exported wrapper recommended
}

Try / catch

archive, err := update.unzip(path, cmd)
if err != nil {
  if isCannotDecompress(err) {
    // delete the corrupt file and re-download before retrying
    os.Remove(path)
    return reDownloadAndRetry()
  }
  return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03). Data as JSON: /api/errors/0346e3c08a0922e7. Report an issue: GitHub.