{"record":{"id":"aa355f5034274f77","repo":"crowdsecurity/crowdsec","slug":"while-opening-s-w-aa355f","errorCode":null,"errorMessage":"while opening %s: %w","messagePattern":"while opening (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubops/download.go","lineNumber":189,"sourceCode":"\t\treturn err\n\t}\n\n\tdownloaded, _, err := i.FetchContentTo(ctx, c.contentProvider, finalPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", i.FQName(), err)\n\t}\n\n\tif downloaded {\n\t\tplan.ReloadNeeded = true\n\t}\n\n\ti.State.Tainted = false\n\ti.State.UpToDate = true\n\n\t// read content to get the list of data files\n\treader, err := os.Open(finalPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while opening %s: %w\", finalPath, err)\n\t}\n\n\tdefer reader.Close()\n\n\tneedReload, err := downloadDataSet(ctx, plan.hub.GetDataDir(), c.Force, reader)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while downloading data for %s: %w\", i.FileName, err)\n\t}\n\n\tif needReload {\n\t\tplan.ReloadNeeded = true\n\t}\n\n\treturn nil\n}\n\nfunc (*DownloadCommand) OperationType() string {\n\treturn \"download\"","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubops/download.go#L171-L207","documentation":"Thrown when os.Open fails on finalPath — the local archive/file just fetched by FetchContentTo — immediately before parsing it to enumerate data files. The hub treats this as an internal inconsistency: it just downloaded or located the file, so it should be openable.","triggerScenarios":"During download Run, after FetchContentTo reported success, opening finalPath fails: the file was deleted between fetch and open, path is wrong on a custom hub/data dir, or permission bits deny the crowdsec user read access.","commonSituations":"Custom HUB_DIR/data dir with restrictive ownership; antivirus/cleanup job removing the archive; racing two crowdsec/cscli processes that both manage the hub directory.","solutions":["Check finalPath (shown in the message) exists and is readable by the user running crowdsec: `ls -l <finalPath>`.","Fix ownership/permissions (e.g. `chown -R crowdsec:crowdsec /var/lib/crowdsec/data`).","Ensure only one process manages the hub dir; re-run the download command to re-fetch the file.","If using custom config paths, verify config.yaml hub/data directory settings are consistent."],"exampleFix":"// before: running cscli as a user that cannot read the data dir\n// after\nsudo chown -R crowdsec:crowdsec /var/lib/crowdsec\ncscli hub update","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(finalPath); err != nil || fi.IsDir() {\n    return fmt.Errorf(\"expected downloaded archive at %s, got none\", finalPath)\n}","typeGuard":null,"tryCatchPattern":"reader, err := os.Open(finalPath)\nif err != nil {\n    if os.IsNotExist(err) {\n        // re-fetch the content then retry once\n    }\n    return err\n}","preventionTips":["Ensure the user running crowdsec/cscli owns or can read the hub data directory.","Avoid concurrent cscli/crowdsec processes managing the same hub directory.","Exclude the data directory from aggressive cleanup/antivirus jobs.","Keep custom config hub/data paths consistent with actual ownership."],"tags":["filesystem","file-open","hub"],"backgroundTag":"file-open-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"}