{"record":{"id":"d3357f78b384b1c8","repo":"crowdsecurity/crowdsec","slug":"failed-opening-s-w","errorCode":null,"errorMessage":"failed opening %s: %w","messagePattern":"failed opening (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/file/run.go","lineNumber":376,"sourceCode":"\t\t\t// we're tailing, it must be real time logs\n\t\t\tlogger.Debugf(\"pushing %+v\", l)\n\n\t\t\tevt := pipeline.MakeEvent(s.config.UseTimeMachine, pipeline.LOG, true)\n\t\t\tevt.Line = l\n\n\t\t\tout <- evt\n\t\t}\n\t}\n}\n\nfunc (s *Source) readFile(ctx context.Context, filename string, out chan pipeline.Event) error {\n\tvar scanner *bufio.Scanner\n\n\tlogger := s.logger.WithField(\"oneshot\", filename)\n\n\tfd, err := os.Open(filename)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed opening %s: %w\", filename, err)\n\t}\n\n\tdefer fd.Close()\n\n\tif strings.HasSuffix(filename, \".gz\") {\n\t\tgz, err := gzip.NewReader(fd)\n\t\tif err != nil {\n\t\t\tlogger.Errorf(\"Failed to read gz file: %s\", err)\n\t\t\treturn fmt.Errorf(\"failed to read gz %s: %w\", filename, err)\n\t\t}\n\n\t\tdefer gz.Close()\n\n\t\tscanner = bufio.NewScanner(gz)\n\t} else {\n\t\tscanner = bufio.NewScanner(fd)\n\t}\n","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/file/run.go#L358-L394","documentation":"readFile is the one-shot (-reader / cscli replay) path: it opens the given log file to replay its lines. If os.Open fails, it returns \"failed opening %s: %w\". The named file simply could not be opened for reading.","triggerScenarios":"os.Open(filename) errors in readFile, invoked by OneShot mode when a user replays a file into crowdsec.","commonSituations":"Typo in the file path passed to cscli/crowdsec -reader; file not readable by the current user; expecting relative path but running from a different directory.","solutions":["Verify the path: run `ls -l <path>` exactly as passed on the command line.","Check read permission on the file and traverse permission on parent directories.","Use an absolute path to avoid cwd confusion.","Check the wrapped OS error: ENOENT = missing file, EACCES = permission."],"exampleFix":"// before\ncrowdsec -file ./logs/applog.log -type syslog\n// after\ncrowdsec -file /var/log/auth.log -type syslog","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nif (!fs.existsSync(path) || !fs.statSync(path).isFile()) {\n  throw new Error(`replay file not found: ${path}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass absolute paths to -file / cscli replay commands.","Verify with `ls -l` before running one-shot replay.","Check the wrapped OS error to distinguish ENOENT from EACCES."],"tags":["file-io","oneshot","go","cli"],"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-14T00:17:10.932Z"}