{"record":{"id":"b2816833879dfa51","repo":"abiosoft/colima","slug":"error-reading-file-for-sha-validation-w","errorCode":null,"errorMessage":"error reading file for SHA validation: %w","messagePattern":"error reading file for SHA validation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/downloader/sha.go","lineNumber":53,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot open file for validation: %w\", err)\n\t}\n\tdefer func() { _ = f.Close() }()\n\n\t// select hash algorithm\n\tvar h hash.Hash\n\tswitch s.Size {\n\tcase 256:\n\t\th = sha256.New()\n\tcase 512:\n\t\th = sha512.New()\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported SHA size: %d (must be 256 or 512)\", s.Size)\n\t}\n\n\t// compute hash\n\tif _, err := io.Copy(h, f); err != nil {\n\t\treturn fmt.Errorf(\"error reading file for SHA validation: %w\", err)\n\t}\n\n\t// compare\n\tcomputed := fmt.Sprintf(\"%x\", h.Sum(nil))\n\texpected := strings.TrimPrefix(s.Digest, fmt.Sprintf(\"sha%d:\", s.Size))\n\texpected = strings.ToLower(strings.TrimSpace(expected))\n\n\tif computed != expected {\n\t\treturn &SHAValidationError{\n\t\t\tFile:     filepath.Base(file),\n\t\t\tExpected: expected,\n\t\t\tActual:   computed,\n\t\t\tSize:     s.Size,\n\t\t}\n\t}\n\n\treturn nil\n}","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/util/downloader/sha.go#L35-L71","documentation":"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.","triggerScenarios":"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.","commonSituations":"Failing disks; cache on external/network storage; concurrent truncation by cleanup tools.","solutions":["Clear the cache entry and re-download the file","Move the cache dir to healthy local storage","Run disk verification (Disk Utility, smartctl, fsck)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := sha.ValidateFile(host, path); err != nil {\n    if strings.Contains(err.Error(), \"error reading file for SHA validation\") {\n        _ = os.Remove(path) // unreadable local copy\n        // re-download, then validate again\n    }\n    return err\n}","preventionTips":["Keep the cache on healthy local storage; hashing stresses reads as much as writes","Treat read-during-hash failures as corrupted cache and discard the entry"],"tags":["filesystem","io","sha","disk"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}