{"record":{"id":"6c187260ebbca86a","repo":"crowdsecurity/crowdsec","slug":"s-latest-hash-missing-from-index-the-index-file","errorCode":null,"errorMessage":"%s: latest hash missing from index. The index file is invalid, please run 'cscli hub update' and try again","messagePattern":"(.+?): latest hash missing from index\\. The index file is invalid, please run 'cscli hub update' and try again","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cwhub/fetch.go","lineNumber":69,"sourceCode":"\tif gotHash != wantHash {\n\t\treturn fmt.Errorf(\"%w. The index file is invalid, please run 'cscli hub update' and try again\",\n\t\t\tdownloader.HashMismatchError{\n\t\t\t\tExpected: wantHash,\n\t\t\t\tGot: gotHash,\n\t\t\t})\n\t}\n\n\treturn nil\n}\n\n// FetchContentTo writes the last version of the item's YAML file to the specified path.\n// If the file is embedded in the index file, it will be written directly without downloads.\n// Returns whether the file was downloaded (to inform if the security engine needs reloading)\n// and the remote url for feedback purposes.\nfunc (i *Item) FetchContentTo(ctx context.Context, contentProvider ContentProvider, destPath string) (bool, string, error) {\n\twantHash := i.latestHash()\n\tif wantHash == \"\" {\n\t\treturn false, \"\", fmt.Errorf(\"%s: latest hash missing from index. The index file is invalid, please run 'cscli hub update' and try again\", i.FQName())\n\t}\n\n\t// Use the embedded content if available\n\tif i.Content != \"\" {\n\t\tif err := i.writeEmbeddedContentTo(destPath, wantHash); err != nil {\n\t\t\treturn false, \"\", err\n\t\t}\n\n\t\ti.State.DownloadPath = destPath\n\n\t\treturn true, fmt.Sprintf(\"(embedded in %s)\", i.hub.local.HubIndexFile), nil\n\t}\n\n\tdownloaded, _, err := contentProvider.FetchContent(ctx, i.RemotePath, destPath, wantHash, i.hub.logger)\n\n\tif err == nil && downloaded {\n\t\ti.State.DownloadPath = destPath\n\t}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/fetch.go#L51-L87","documentation":"FetchContentTo needs the item's latest content hash to validate whatever it writes. If i.latestHash() returns empty, the index entry is missing its hash metadata, and the item cannot be safely fetched, so it errors with a directive to re-download the index.","triggerScenarios":"Calling FetchContentTo (e.g. via itemDiff during hub sync/upgrade) for an item whose index entry lacks the latest hash — index missing the version/hash fields for that item.","commonSituations":"Corrupted or truncated .index.json, index downloaded by an older cscli version with a different schema, manual edits, or a hub-side item whose metadata was not fully published.","solutions":["Run `sudo cscli hub update` to download a fresh index","If it persists, remove /var/lib/crowdsec/data/hub/.index.json and run `cscli hub update` again","Ensure cscli/crowdsec version matches the hub index schema (upgrade if outdated)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for _, it := range items {\n    if it.LatestHash == \"\" {\n        return fmt.Errorf(\"item %s has no hash in index; run 'cscli hub update'\", it.Name)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := item.FetchContentTo(ctx, provider, dest); err != nil {\n    if strings.Contains(err.Error(), \"latest hash missing from index\") {\n        return refreshHubIndexAndRetry(ctx)\n    }\n    return err\n}","preventionTips":["Keep the index fresh: schedule periodic `cscli hub update`","Validate index entries (non-empty hashes) after download before syncing","Never truncate or manually edit the index file"],"tags":["hub","index","hash","metadata"],"backgroundTag":"missing-config-value","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"}