{"record":{"id":"d6d20929d0301b71","repo":"crowdsecurity/crowdsec","slug":"failed-to-parse-index-w","errorCode":null,"errorMessage":"failed to parse index: %w","messagePattern":"failed to parse index: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cwhub/hub.go","lineNumber":78,"sourceCode":"func (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\n\t\t\tif (itemType == PARSERS || itemType == POSTOVERFLOWS) && item.Stage == \"\" {\n\t\t\t\treturn fmt.Errorf(\"%s:%s has no stage\", itemType, name)\n\t\t\t}\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/hub.go#L60-L96","documentation":"parseIndex fails when the hub index file content is not valid JSON for the expected items map structure, reported by json.Unmarshal. The file exists and is readable, but its contents are corrupt or in an unexpected format.","triggerScenarios":"Hub.Load → parseIndex when .index.json is truncated by an interrupted download, hand-edited with syntax errors, or written by an incompatible hub/cscli version.","commonSituations":"Interrupted `cscli hub update` (partial file), disk corruption, manual modification, or an index fetched through a proxy that returned an HTML error page instead of JSON.","solutions":["Run `sudo cscli hub update` to re-download a valid index","Delete the corrupt file and run `cscli hub update` again: `rm /var/lib/crowdsec/data/hub/.index.json`","Validate the file with `jq . <file>` to see the exact JSON error and location","Check proxy/firewall is not injecting content into hub downloads"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"bidx, err := os.ReadFile(indexFile)\nif err == nil {\n    var probe map[string]json.RawMessage\n    if err := json.Unmarshal(bidx, &probe); err != nil {\n        return fmt.Errorf(\"index is corrupt (%v); run 'cscli hub update'\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := hub.Load(); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse index\") {\n        logger.Error(\"corrupt hub index; removing and re-downloading\")\n        os.Remove(indexFile)\n        if uerr := runHubUpdate(ctx); uerr != nil { return uerr }\n        return hub.Load()\n    }\n    return err\n}","preventionTips":["Don't hand-edit .index.json; regenerate it via `cscli hub update`","Ensure downloads complete atomically (the downloader uses temp files — don't bypass it)","Check that proxies don't inject HTML into hub downloads"],"tags":["json","hub","index","corruption"],"backgroundTag":"json-unmarshal-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"}