{"record":{"id":"e48b25f4840328db","repo":"abiosoft/colima","slug":"cannot-open-file-for-validation-w","errorCode":null,"errorMessage":"cannot open file for validation: %w","messagePattern":"cannot open file for validation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/downloader/sha.go","lineNumber":36,"sourceCode":"// SHA is the shasum of a file.\ntype SHA struct {\n\tDigest string // shasum\n\tURL    string // url to download the shasum file (if Digest is empty)\n\tSize   int    // one of 256 or 512\n}\n\n// ValidateFile validates the SHA of the file.\n// The host parameter is kept for API compatibility but is not used.\nfunc (s SHA) ValidateFile(host hostActions, file string) error {\n\treturn s.validateFile(file)\n}\n\n// validateFile performs SHA validation using pure Go crypto.\nfunc (s SHA) validateFile(file string) error {\n\t// open the file\n\tf, err := os.Open(file)\n\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}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/util/downloader/sha.go#L18-L54","documentation":"validateFile could not os.Open the file it is about to hash. The wrapped *fs.PathError means the path does not exist (ENOENT), is a directory, or is unreadable (EACCES). In the internal flow the file was just written, so this mostly appears when SHA.ValidateFile is called directly with a stale path or the cache entry vanished between download and validation.","triggerScenarios":"Calling SHA.ValidateFile with a path whose file was moved/deleted (cache cleared mid-operation); wrong path (relative vs absolute, typo); file without read permission for the current user.","commonSituations":"Cache purged while an operation runs; validating a file after it was relocated; validating inside a context with reduced permissions.","solutions":["ls -l the exact path from the error and correct it","Re-run the download to regenerate the cache entry","Check read permission on the file and every parent directory"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(path); err != nil {\n    return fmt.Errorf(\"cache entry missing, re-download before validating: %w\", err)\n} else if fi.IsDir() {\n    return errors.New(\"validation target is a directory, expected a file\")\n}\nerr := sha.ValidateFile(host, path)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stat the file immediately before validating; never cache paths across long operations","Derive the path from downloader.CacheFilename instead of hand-built strings"],"tags":["filesystem","sha","validation"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}