{"record":{"id":"935d78ef080f6cf2","repo":"crowdsecurity/crowdsec","slug":"unable-to-stat-log-file-s-w","errorCode":null,"errorMessage":"unable to stat log file '%s': %w","messagePattern":"unable to stat log file '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":472,"sourceCode":"\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (t *HubTestItem) RunWithLogFile(ctx context.Context) error {\n\ttestPath := filepath.Join(t.HubTestPath, t.Name)\n\tif _, err := os.Stat(testPath); os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"test '%s' doesn't exist in '%s', exiting\", t.Name, t.HubTestPath)\n\t}\n\n\tlogFile := filepath.Join(testPath, t.Config.LogFile)\n\tlogType := t.Config.LogType\n\tdsn := \"file://\" + logFile\n\n\tlogFileStat, err := os.Stat(logFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to stat log file '%s': %w\", logFile, err)\n\t}\n\n\tif logFileStat.Size() == 0 {\n\t\treturn fmt.Errorf(\"log file '%s' is empty, please fill it with log\", logFile)\n\t}\n\n\tcmdArgs := []string{\"-c\", t.RuntimeConfigFilePath, \"machines\", \"add\", \"testMachine\", \"--force\", \"--auto\"}\n\tcscliRegisterCmd := exec.CommandContext(ctx, t.CscliPath, cmdArgs...)\n\tcscliRegisterCmd.Dir = testPath\n\tcscliRegisterCmd.Env = []string{\"TESTDIR=\" + testPath, \"DATADIR=\" + t.RuntimeHubConfig.InstallDataDir, \"TZ=UTC\"}\n\n\tlog.Debugf(\"%s\", cscliRegisterCmd.String())\n\n\toutput, err := cscliRegisterCmd.CombinedOutput()\n\tif err != nil {\n\t\tif !strings.Contains(string(output), \"unable to create machine: user 'testMachine': user already exist\") {\n\t\t\tfmt.Fprintln(os.Stdout, string(output))\n\t\t\treturn fmt.Errorf(\"fail to run '%s' for test '%s': %w\", cscliRegisterCmd.String(), t.Name, err)","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L454-L490","documentation":"RunWithLogFile stats the test's input log file (the log sample that will be fed to crowdsec via a file:// datasource); a stat failure aborts the test with this error. It is distinct from the missing-test-directory error: the test dir exists but the configured log file inside it does not.","triggerScenarios":"os.Stat(logFile) fails where logFile = <testPath>/<t.Config.LogFile>: the file named in the test's .config.yaml (LogType/LogFile) is absent, the config path is wrong, or permission denies access.","commonSituations":"Test config 'log_file' key renamed/renamed file not committed; empty repo checkout missing the sample log; running tests from a different working directory so relative paths resolve elsewhere; symlink to a file the user cannot read.","solutions":["Verify the file exists: ls <testdir>/<log_file from .config.yaml>","Fix the LogFile value in the test's .config.yaml to match the actual sample filename","Restore/checkout the missing sample log file (git checkout -- <path>)","Check read permissions on the file and its parent directory"],"exampleFix":"// before (.config.yaml)\nlog_file: logs/app.log   # file actually named sample.log\n// after\nlog_file: sample.log","handlingStrategy":"validation","validationCode":"logFile := filepath.Join(testPath, cfg.LogFile)\nif fi, err := os.Stat(logFile); err != nil || fi.Size() == 0 {\n\treturn fmt.Errorf(\"log sample %s missing or empty\", logFile)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the sample log file committed and named exactly as in .config.yaml","Run tests from the repo root so relative config paths resolve","Validate test fixtures with a pre-flight stat before running the suite"],"tags":["filesystem","test-harness","config","not-found"],"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"}