{"record":{"id":"746c6a45b99203a5","repo":"crowdsecurity/crowdsec","slug":"failed-to-sync-s-w","errorCode":null,"errorMessage":"failed to sync %s: %w","messagePattern":"failed to sync (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cwhub/sync.go","lineNumber":514,"sourceCode":"\tfor _, v := range sl {\n\t\tif _, ok := seen[v]; ok {\n\t\t\tcontinue\n\t\t}\n\n\t\tseen[v] = struct{}{}\n\t\tsl[j] = v\n\t\tj++\n\t}\n\n\treturn sl[:j]\n}\n\n// localSync updates the hub state with downloaded, installed and local items.\nfunc (h *Hub) localSync() error {\n\t// add downloaded files first, so they can find the place in the index\n\t// before it's overridden by local items in case of name collision\n\tif err := h.syncDir(h.local.HubDir); err != nil {\n\t\treturn fmt.Errorf(\"failed to sync %s: %w\", h.local.HubDir, err)\n\t}\n\n\tif err := h.syncDir(h.local.InstallDir); err != nil {\n\t\treturn fmt.Errorf(\"failed to sync %s: %w\", h.local.InstallDir, err)\n\t}\n\n\twarnings := make([]string, 0)\n\n\tfor _, item := range h.GetItemMap(COLLECTIONS) {\n\t\t// check for cyclic dependencies\n\t\tsubs, err := item.descendants()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// populate the sub- and sub-sub-items with the collections they belong to\n\t\tfor _, sub := range subs {\n\t\t\tsub.State.BelongsToCollections = insertInOrderNoCase(sub.State.BelongsToCollections, item.Name)","sourceCodeStart":496,"sourceCodeEnd":532,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/sync.go#L496-L532","documentation":"localSync refreshes the hub state by scanning the hub directory (downloaded items) first; any error returned by syncDir is wrapped as 'failed to sync <HubDir>'. This means walking/collecting items under the hub working directory failed, so the whole Load aborts with the inner cause (bad path layout, unreadable file, etc.) prefixed by the directory that failed.","triggerScenarios":"Hub.Load calls localSync; syncDir(h.local.HubDir) returns an error from any item visited under the hub dir, e.g. newHubItemSpec path errors, unreadable files, or a broken walk due to permissions.","commonSituations":"Corrupted or hand-modified hub directory tree; hub dir partially deleted while crowdsec starts; hub dir on a mount that lost permissions; running with a HUBDIR pointing at a nonexistent or wrong-depth tree.","solutions":["Read the inner wrapped error (%w) to identify the offending file, and fix it per that specific cause","Reset the hub state: 'cscli hub update' then 'cscli hub upgrade' to restore a clean tree","Verify HUBDIR in config.yaml points to the correct hub working directory with the expected layout"],"exampleFix":"// before: config.yaml\nhub_dir: /etc/crowdsec/data/hub  # wrong: tree lacking <type>/<author>/<file> depth\n// after\nhub_dir: /etc/crowdsec/hub\ncscli hub update","handlingStrategy":"try-catch","validationCode":"func checkHubDir(hubDir string) error {\n\tinfo, err := os.Stat(hubDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !info.IsDir() {\n\t\treturn fmt.Errorf(\"%s is not a directory\", hubDir)\n\t}\n\treturn nil\n}\n// also confirm config.yaml hub_dir matches 'cscli hub list' expectations","typeGuard":null,"tryCatchPattern":"if err := hub.Load(ctx); err != nil {\n\tif strings.Contains(err.Error(), \"failed to sync \"+hubDir) {\n\t\treturn fmt.Errorf(\"hub dir broken (%v); run 'cscli hub update'\", errors.Unwrap(err))\n\t}\n\treturn err\n}","preventionTips":["Fix the root cause by unwrapping errors.Unwrap() to reach the specific file problem","Restore the hub with cscli hub update / upgrade instead of manually patching the tree","Pin HUBDIR in config.yaml and don't relocate it without reinstalling items"],"tags":["hub","sync","directory","startup","crowdsec"],"backgroundTag":"directory-sync-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"}