anomalyco/sst · error

failed to hash file: %w

Error message

failed to hash file: %w

What it means

hashFileContents wraps io.Copy into the sha256 hasher with this message. The file opened fine, but reading its bytes into the hasher failed — an I/O error on read. Thrown from copySyncedDependencies during dev-mode change detection.

Source

Thrown at pkg/runtime/python/python.go:464

		dstPath := filepath.Join(dst, relPath)
		if info.IsDir() {
			return os.MkdirAll(dstPath, info.Mode())
		}
		return copyFile(p, dstPath)
	})
}

// hashFileContents computes a SHA256 hash of a file's contents.
func hashFileContents(filePath string) (string, error) {
	file, err := os.Open(filePath)
	if err != nil {
		return "", fmt.Errorf("failed to open file for hashing: %w", err)
	}
	defer file.Close()

	hasher := sha256.New()
	if _, err := io.Copy(hasher, file); err != nil {
		return "", fmt.Errorf("failed to hash file: %w", err)
	}

	return hex.EncodeToString(hasher.Sum(nil)), nil
}

// hasWorkspaceLayoutPatterns checks for package/src/package patterns that need flattening.
// Scans up to one level below projectRoot to cover both single-package and monorepo layouts.
func (r *PythonRuntime) hasWorkspaceLayoutPatterns(projectRoot string) bool {
	var scan func(dir string, depth int) bool
	scan = func(dir string, depth int) bool {
		entries, err := os.ReadDir(dir)
		if err != nil {
			return false
		}
		for _, entry := range entries {
			name := entry.Name()
			if !entry.IsDir() || strings.HasPrefix(name, ".") || name == "__pycache__" || name == "node_modules" {
				continue

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Re-run the sync — transient I/O errors usually clear
  2. Check dmesg/OS logs for underlying disk or network filesystem errors
  3. Avoid hashing while package managers rewrite the same files (pause/lock concurrent processes)
  4. Copy to local temp storage before hashing if files live on remote mounts
Defensive patterns

Strategy: retry

Validate before calling

null

Try / catch

if err := sstDev(); err != nil {
	if strings.Contains(err.Error(), "failed to hash file") {
		// transient read I/O error: wait and re-run sync
	}
}

Prevention

When it happens

Trigger: io.Copy(hasher, file) errors while hashing a synced dependency: source file on flaky/networked storage, file truncated by a concurrent writer mid-hash, or a special file that errors on read.

Common situations: Hashing files on an NFS/EFS mount that hiccups; another process (formatter, package manager) rewriting the file concurrently during `sst dev`; sparse or damaged file with underlying block errors.

Related errors


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