anomalyco/sst · error

failed to extract archive: %w

Error message

failed to extract archive: %w

What it means

When the matched archive is a `.tar.gz` (sdist), `processPackageArchive` extracts it with `extractTarGz`. This error wraps failure of that extraction — invalid gzip data, corrupt tar stream, or filesystem errors during unpacking.

Source

Thrown at pkg/runtime/python/build.go:323

	return nil
}

// processPackageArchive extracts and cleans up a single package archive
func processPackageArchive(archiveFile, outputDir string) error {
	if strings.HasSuffix(archiveFile, ".whl") {
		if err := extractZip(archiveFile, outputDir); err != nil {
			return fmt.Errorf("failed to extract wheel: %w", err)
		}

		os.Remove(archiveFile)

		return nil
	}

	// Extract tar.gz
	if err := extractTarGz(archiveFile, outputDir); err != nil {
		return fmt.Errorf("failed to extract archive: %w", err)
	}

	// Get the directory name without version number
	archiveBaseName := filepath.Base(archiveFile)
	dirName := strings.TrimSuffix(archiveBaseName, ".tar.gz")
	lastHyphen := strings.LastIndex(dirName, "-")
	if lastHyphen == -1 {
		return fmt.Errorf("invalid archive name format: %s", archiveBaseName)
	}

	baseName := dirName[:lastHyphen]
	extractedDir := filepath.Join(outputDir, dirName)
	targetDir := filepath.Join(outputDir, baseName)

	// Move extracted directory to target
	if err := moveExtractedPackage(extractedDir, targetDir, baseName); err != nil {
		return fmt.Errorf("failed to move extracted package: %w", err)
	}

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Delete the corrupt .tar.gz from the build output and rebuild
  2. Validate the file: `tar -tzf <file>.tar.gz` should list entries without errors
  3. Check disk space and write permissions on outputDir
  4. Bypass unreliable mirrors by pointing pip at official PyPI

Example fix

// before: private mirror serving corrupt sdists
// after: pin to official PyPI
pip config set global.index-url https://pypi.org/simple
Defensive patterns

Strategy: validation

Validate before calling

import { execSync } from "child_process";
execSync(`tar -tzf ${archivePath}`, { stdio: "ignore" }); // throws if corrupt

Try / catch

try {
  await buildPackage(...);
} catch (e) {
  if (String(e).includes("failed to extract archive")) {
    console.error("Invalid tar.gz sdist — rebuild from a clean output dir:", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Glob matched a `*.tar.gz` file that is not a valid gzip/tar (partial download, wrong file), or the output directory is not writable during extraction.

Common situations: Proxied/network errors saving HTML as .tar.gz; disk space exhaustion mid-extract; corrupted sdist from a private PyPI mirror.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/c83fa5ddec283c0d. Report an issue: GitHub.