{"record":{"id":"5284a95924410906","repo":"crowdsecurity/crowdsec","slug":"unable-to-read-index-file-w","errorCode":null,"errorMessage":"unable to read index file: %w","messagePattern":"unable to read index file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cwhub/hub.go","lineNumber":74,"sourceCode":"\treturn hub, nil\n}\n\n// Load reads the state of the items on disk.\nfunc (h *Hub) Load() error {\n\th.logger.Debugf(\"loading hub idx %s\", h.local.HubIndexFile)\n\n\tif err := h.parseIndex(); err != nil {\n\t\treturn fmt.Errorf(\"invalid hub index: %w. Run 'sudo cscli hub update' to download the index again\", err)\n\t}\n\n\treturn h.localSync()\n}\n\n// parseIndex takes the content of an index file and fills the map of associated parsers/scenarios/collections.\nfunc (h *Hub) parseIndex() error {\n\tbidx, err := os.ReadFile(h.local.HubIndexFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to read index file: %w\", err)\n\t}\n\n\tif err := json.Unmarshal(bidx, &h.items); err != nil {\n\t\treturn fmt.Errorf(\"failed to parse index: %w\", err)\n\t}\n\n\t// Iterate over the different types to complete the struct\n\tfor _, itemType := range ItemTypes {\n\t\tfor name, item := range h.GetItemMap(itemType) {\n\t\t\tif item == nil {\n\t\t\t\t// likely defined as empty object or null in the index file\n\t\t\t\treturn fmt.Errorf(\"%s:%s has no index metadata\", itemType, name)\n\t\t\t}\n\n\t\t\tif item.RemotePath == \"\" {\n\t\t\t\treturn fmt.Errorf(\"%s:%s has no download path\", itemType, name)\n\t\t\t}\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/hub.go#L56-L92","documentation":"parseIndex reports failure to read the hub index file from h.local.HubIndexFile with os.ReadFile. The wrapped os error distinguishes not-exists, permission-denied, is-a-directory, etc. This makes Hub.Load fail before any JSON parsing.","triggerScenarios":"Hub.Load → parseIndex when the index file does not exist (no prior hub update), the path points to a directory, or the process lacks read permission.","commonSituations":"Fresh install without `cscli hub update`, running cscli as a non-root user against root-owned /var/lib/crowdsec, wrong config point to a custom data_dir without an index, or accidentally deleting the file.","solutions":["Run `sudo cscli hub update` to create/download the index file","Check file existence and permissions: `ls -l /var/lib/crowdsec/data/hub/.index.json`","Run the command as root or fix ownership (`chown -R` the crowdsec data dir)","Verify local.data_dir in config points at the directory that actually holds the index"],"exampleFix":"// before\ncscli hub list   # as unprivileged user, index root-owned\n// after\nsudo cscli hub list","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(indexFile)\nif err != nil {\n    return fmt.Errorf(\"hub index not readable: %w — run 'cscli hub update'\", err)\n}\nif fi.IsDir() || fi.Size() == 0 {\n    return fmt.Errorf(\"hub index %s is not a regular non-empty file\", indexFile)\n}","typeGuard":null,"tryCatchPattern":"if err := hub.Load(); err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrNotExist) {\n        logger.Error(\"hub index missing; run 'sudo cscli hub update'\")\n        return\n    }\n    return err\n}","preventionTips":["Run `cscli hub update` on first install before any hub operation","Run cscli with privileges to read /var/lib/crowdsec (or align ownership)","Point local.data_dir at the directory that actually contains the index"],"tags":["filesystem","file-read","hub","index"],"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-14T05:17:10.506Z"}