crowdsecurity/crowdsec · error

log file '%s' is empty, please fill it with log

Error message

log file '%s' is empty, please fill it with log

What it means

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.

Source

Thrown at pkg/hubtest/hubtest_item.go:476

}

func (t *HubTestItem) RunWithLogFile(ctx context.Context) error {
	testPath := filepath.Join(t.HubTestPath, t.Name)
	if _, err := os.Stat(testPath); os.IsNotExist(err) {
		return fmt.Errorf("test '%s' doesn't exist in '%s', exiting", t.Name, t.HubTestPath)
	}

	logFile := filepath.Join(testPath, t.Config.LogFile)
	logType := t.Config.LogType
	dsn := "file://" + logFile

	logFileStat, err := os.Stat(logFile)
	if err != nil {
		return fmt.Errorf("unable to stat log file '%s': %w", logFile, err)
	}

	if logFileStat.Size() == 0 {
		return fmt.Errorf("log file '%s' is empty, please fill it with log", logFile)
	}

	cmdArgs := []string{"-c", t.RuntimeConfigFilePath, "machines", "add", "testMachine", "--force", "--auto"}
	cscliRegisterCmd := exec.CommandContext(ctx, t.CscliPath, cmdArgs...)
	cscliRegisterCmd.Dir = testPath
	cscliRegisterCmd.Env = []string{"TESTDIR=" + testPath, "DATADIR=" + t.RuntimeHubConfig.InstallDataDir, "TZ=UTC"}

	log.Debugf("%s", cscliRegisterCmd.String())

	output, err := cscliRegisterCmd.CombinedOutput()
	if err != nil {
		if !strings.Contains(string(output), "unable to create machine: user 'testMachine': user already exist") {
			fmt.Fprintln(os.Stdout, string(output))
			return fmt.Errorf("fail to run '%s' for test '%s': %w", cscliRegisterCmd.String(), t.Name, err)
		}
	}

	cmdArgs = []string{"-c", t.RuntimeConfigFilePath, "-type", logType, "-dsn", dsn, "-dump-data", t.ResultsPath, "-order-event"}

View on GitHub (pinned to 909b515798)

Solutions

  1. Put real log lines into the test's log file referenced by the hubtest config
  2. Verify the log file path in the test yaml matches the file you populated
  3. Check for CI checkout issues (git LFS, .gitignore filtering) that leave the file empty

Example fix

// before
touch tests/test01/file.log
// after
printf '%s\n' 'Sep  1 10:00:00 host sshd[123]: Failed password for root from 1.2.3.4' > tests/test01/file.log
Defensive patterns

Strategy: validation

Validate before calling

st, err := os.Stat(logFile); if err != nil || st.Size() == 0 { t.Fatalf("test log file %q missing or empty", logFile) }

Try / catch

if err := t.Run(ctx); err != nil { if strings.Contains(err.Error(), "is empty, please fill it with log") { /* fix fixture and retry */ } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/26579d038c64b5cb. Report an issue: GitHub.