abiosoft/colima · error

error reading file for SHA validation: %w

Error message

error reading file for SHA validation: %w

What it means

The file opened successfully but io.Copy into the hash failed while reading — an I/O error on read (bad sectors, file truncated externally, dropped network volume). The URL and digest are fine; the local read failed while hashing.

Source

Thrown at util/downloader/sha.go:53

	if err != nil {
		return fmt.Errorf("cannot open file for validation: %w", err)
	}
	defer func() { _ = f.Close() }()

	// select hash algorithm
	var h hash.Hash
	switch s.Size {
	case 256:
		h = sha256.New()
	case 512:
		h = sha512.New()
	default:
		return fmt.Errorf("unsupported SHA size: %d (must be 256 or 512)", s.Size)
	}

	// compute hash
	if _, err := io.Copy(h, f); err != nil {
		return fmt.Errorf("error reading file for SHA validation: %w", err)
	}

	// compare
	computed := fmt.Sprintf("%x", h.Sum(nil))
	expected := strings.TrimPrefix(s.Digest, fmt.Sprintf("sha%d:", s.Size))
	expected = strings.ToLower(strings.TrimSpace(expected))

	if computed != expected {
		return &SHAValidationError{
			File:     filepath.Base(file),
			Expected: expected,
			Actual:   computed,
			Size:     s.Size,
		}
	}

	return nil
}

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Clear the cache entry and re-download the file
  2. Move the cache dir to healthy local storage
  3. Run disk verification (Disk Utility, smartctl, fsck)
Defensive patterns

Strategy: try-catch

Try / catch

if err := sha.ValidateFile(host, path); err != nil {
    if strings.Contains(err.Error(), "error reading file for SHA validation") {
        _ = os.Remove(path) // unreadable local copy
        // re-download, then validate again
    }
    return err
}

Prevention

When it happens

Trigger: Storage fault while hashing a multi-hundred-MB image; the file is truncated by another process during hashing; cache lives on a volume that unmounted mid-read.

Common situations: Failing disks; cache on external/network storage; concurrent truncation by cleanup tools.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/b2816833879dfa51. Report an issue: GitHub.