anomalyco/sst · error

failed to open file for hashing

Error message

failed to open file for hashing: %w

What it means

hashFileContents opens a file to compute its SHA256 and wraps os.Open failures with this message. The library throws it from copySyncedDependencies, which hashes files to detect changes for dev-mode sync. It means the file that the dependency list referenced could not be opened for reading at hash time.

Solutions

  1. Verify the file exists at the hashed path (ls / stat) and recreate it if it was deleted
  2. Restart `sst dev` so the dependency list and hashes are recomputed
  3. Check file permissions/ownership of the dependency files
  4. If files are frequently mid-write, ignore ENOENT for files that vanished during sync
Defensive patterns

Strategy: validation

Validate before calling

func fileExists(path string) bool {
	fi, err := os.Stat(path)
	return err == nil && fi.Mode().IsRegular()
}
// before syncing: ensure every dependency path hashes-exists
// if !fileExists(depPath) { recompute dependency list or skip }

Try / catch

if err := sstDev(); err != nil {
	if strings.Contains(err.Error(), "failed to open file for hashing") {
		// file vanished or is unreadable: restart dev to rebuild dependency list
	}
}

Prevention

When it happens

Trigger: copySyncedDependencies calls hashFileContents(path) on a path that no longer exists (file deleted between dependency discovery and hashing) or is unreadable (permissions, symlink to nonexistent target, path too long).

Common situations: File removed by a concurrent build/clean while `sst dev` is syncing; stale cache pointing at an old dependency path; workspace package relocated or renamed; restrictive umask/permissions on files generated by another user (e.g. root in Docker).

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

		if skip(relPath, info) {
			if info.IsDir() {
				return filepath.SkipDir
			}
			return nil
		}
		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 {

View on GitHub (pinned to a0bd20f762)