{"record":{"id":"26579d038c64b5cb","repo":"crowdsecurity/crowdsec","slug":"log-file-s-is-empty-please-fill-it-with-log","errorCode":null,"errorMessage":"log file '%s' is empty, please fill it with log","messagePattern":"log file '(.+?)' is empty, please fill it with log","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":476,"sourceCode":"}\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)\n\t\t}\n\t}\n\n\tcmdArgs = []string{\"-c\", t.RuntimeConfigFilePath, \"-type\", logType, \"-dsn\", dsn, \"-dump-data\", t.ResultsPath, \"-order-event\"}","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L458-L494","documentation":"Hubtest's RunWithLogFile requires the test's log file to contain data before replaying it through crowdsec. Before launching cscli/crowdsec it stats the log file and aborts if the size is 0, because parsing an empty input would produce meaningless assertions.","triggerScenarios":"Calling t.Run() (which invokes RunWithLogFile) for a hubtest whose log file, defined by the test's config (log_file or a DSN-based file), exists but has zero bytes.","commonSituations":"A new hubtest was added with `touch tests/logs/file.log` but the developer never put sample logs in it; a log file was truncated by git LFS checkout failure or cleanup scripts; the log path in the test config points at an empty placeholder.","solutions":["Put real log lines into the test's log file referenced by the hubtest config","Verify the log file path in the test yaml matches the file you populated","Check for CI checkout issues (git LFS, .gitignore filtering) that leave the file empty"],"exampleFix":"// before\ntouch tests/test01/file.log\n// after\nprintf '%s\\n' 'Sep  1 10:00:00 host sshd[123]: Failed password for root from 1.2.3.4' > tests/test01/file.log","handlingStrategy":"validation","validationCode":"st, err := os.Stat(logFile); if err != nil || st.Size() == 0 { t.Fatalf(\"test log file %q missing or empty\", logFile) }","typeGuard":null,"tryCatchPattern":"if err := t.Run(ctx); err != nil { if strings.Contains(err.Error(), \"is empty, please fill it with log\") { /* fix fixture and retry */ } }","preventionTips":["Commit populated sample log fixtures with hubtests","Add a pre-test check that every configured log file is non-empty","Disable git LFS/autocrlf mangling on log fixtures"],"tags":["hubtest","empty-file","testing"],"backgroundTag":"empty-required-field","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"}