{"record":{"id":"fcf7ad865b0dd989","repo":"crowdsecurity/crowdsec","slug":"failed-to-get-sha256-of-s-w","errorCode":null,"errorMessage":"failed to get sha256 of %s: %w","messagePattern":"failed to get sha256 of (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cwhub/sync.go","lineNumber":593,"sourceCode":"\tfor _, version := range sorted {\n\t\tif i.Versions[version].Digest == hash {\n\t\t\treturn version, true, nil\n\t\t}\n\t}\n\n\treturn \"?\", false, nil\n}\n\nfunc (i *Item) setVersionState(path string, inhub bool) error {\n\tvar err error\n\n\tif !inhub {\n\t\ti.State.LocalPath = path\n\t}\n\n\thash, err := downloader.SHA256(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get sha256 of %s: %w\", path, err)\n\t}\n\ti.State.LocalHash = hash\n\n\tversion, found, err := i.detectVersionFromHash(hash)\n\tif err != nil {\n\t\treturn err\n\t}\n\ti.State.LocalVersion = version\n\n\tif !found {\n\t\ti.hub.logger.Tracef(\"got tainted match for %s: %s\", i.Name, path)\n\t\ti.State.UpToDate = false\n\t\ti.addTaint(i)\n\t\treturn nil\n\t}\n\n\t// we got an exact match, update struct\n","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/sync.go#L575-L611","documentation":"Returned by setVersionState when it cannot compute the SHA-256 digest of the downloaded/local item file. The wrap includes the file path and the underlying I/O error, and the item's version detection cannot proceed without the hash.","triggerScenarios":"downloader.SHA256(path) fails because the file does not exist, is a directory, or is unreadable (permissions). Occurs during cscli hub install/update/upgrade when item files were removed or partially written.","commonSituations":"File deleted by an external process after download, permissions changed on /etc/crowdsec or the hub data dir, running as wrong user (permission denied), or path pointing to a directory.","solutions":["Check the file exists and is readable at the reported path (ls -l <path>).","Fix ownership/permissions on the crowdsec config and data directories (chown -R crowdsec:crowdsec /etc/crowdsec /var/lib/crowdsec).","Re-run cscli hub update && cscli hub upgrade to re-download the missing/corrupt file.","Run the command as the user that owns the hub files or with appropriate privileges."],"exampleFix":"// shell\n# before: sha256 fails with permission denied\n$ cscli hub update\n// after: fix permissions then retry\n# chown -R crowdsec:crowdsec /etc/crowdsec /var/lib/crowdsec\n# cscli hub update && cscli hub upgrade","handlingStrategy":"try-catch","validationCode":"if info, err := os.Stat(path); err != nil || info.IsDir() {\n    return fmt.Errorf(\"item file %s missing or not a regular file\", path)\n}","typeGuard":null,"tryCatchPattern":"if err := setVersionState(...); err != nil {\n    if errors.Is(err, fs.ErrPermission) {\n        // advise chown/chmod on crowdsec dirs\n    }\n    if errors.Is(err, fs.ErrNotExist) {\n        // re-run cscli hub update/upgrade\n    }\n    return err\n}","preventionTips":["Run crowdsec/cscli as a user with read access to hub data directories","Avoid external cleanup jobs deleting files under /var/lib/crowdsec","After manual file edits, re-run cscli hub update","Monitor disk for full-disk/partition errors that truncate downloads"],"tags":["go","file-io","sha256"],"backgroundTag":"file-read-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}