{"record":{"id":"390dc19f68086304","repo":"crowdsecurity/crowdsec","slug":"while-opening-s-w-390dc1","errorCode":null,"errorMessage":"while opening %s: %w","messagePattern":"while opening (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubops/datarefresh.go","lineNumber":16,"sourceCode":"package hubops\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/crowdsecurity/crowdsec/pkg/cwhub\"\n)\n\n// XXX: TODO: temporary for hubtests, but will have to go.\n// DownloadDataIfNeeded downloads the data set for the item.\nfunc DownloadDataIfNeeded(ctx context.Context, hub *cwhub.Hub, item *cwhub.Item, force bool) (bool, error) {\n\titemFile, err := os.Open(item.State.LocalPath)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"while opening %s: %w\", item.State.LocalPath, err)\n\t}\n\n\tdefer itemFile.Close()\n\n\tneedReload, err := downloadDataSet(ctx, hub.GetDataDir(), force, itemFile)\n\tif err != nil {\n\t\treturn needReload, fmt.Errorf(\"while downloading data for %s: %w\", item.State.LocalPath, err)\n\t}\n\n\treturn needReload, nil\n}\n\n// DataRefreshCommand updates the data files associated with the installed hub items.\ntype DataRefreshCommand struct {\n\tForce bool\n}\n\nfunc NewDataRefreshCommand(force bool) *DataRefreshCommand {","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubops/datarefresh.go#L1-L34","documentation":"DownloadDataIfNeeded opens the item's local file to refresh its data set. If os.Open fails, the error is wrapped as 'while opening %s: %w'. This usually means the item's LocalPath points to a missing or unreadable file, i.e. the hub state is out of sync with disk.","triggerScenarios":"Calling DownloadDataIfNeeded (via hub update Run or InstallHub) with an item whose State.LocalPath does not exist on disk or is not readable.","commonSituations":"Item was deleted manually from the hub directory but still registered in the hub index; stale .local state after a partial install; permission problem on the config directory.","solutions":["Run 'cscli hub update' or reinstall the item to restore its local file","Check the file at item.State.LocalPath exists and is readable","Fix directory permissions on the hub/config directory","Remove the stale item from the hub index and re-install it"],"exampleFix":"// before\nneedReload, err := hubops.DownloadDataIfNeeded(ctx, hub, item, force)\n// after\nif _, err := os.Stat(item.State.LocalPath); errors.Is(err, fs.ErrNotExist) {\n    item.Download = true // re-fetch before refreshing data\n}\nneedReload, err := hubops.DownloadDataIfNeeded(ctx, hub, item, force)","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(item.State.LocalPath); err != nil || fi.IsDir() {\n    return fmt.Errorf(\"item file missing: %s\", item.State.LocalPath)\n}","typeGuard":null,"tryCatchPattern":"needReload, err := hubops.DownloadDataIfNeeded(ctx, hub, item, force)\nif err != nil {\n    if errors.Is(err, fs.ErrNotExist) { /* mark item for re-download */ }\n    return err\n}","preventionTips":["Keep cscli item state and disk in sync; avoid manual deletes","Use 'cscli hub list' to verify items before operating","Set item.Download=true when the local file is absent"],"tags":["hub","file-open","local-file"],"backgroundTag":"file-not-found","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"}