crowdsecurity/crowdsec · error

error while stats '%s': %w

Error message

error while stats '%s': %w

What it means

After the parse run, hubtest stats the parser assertion file (parser_assert.yaml) to decide between autogeneration and assertion checking. If os.Stat fails (file missing or unreadable) the run aborts with this wrapped error.

Source

Thrown at pkg/hubtest/hubtest_item.go:530

	if err != nil {
		return fmt.Errorf("fail to run '%s' for test '%s': %w", crowdsecCmd.String(), t.Name, err)
	}

	// assert parsers
	if !t.Config.IgnoreParsers {
		_, err := os.Stat(t.ParserAssert.File)
		if os.IsNotExist(err) {
			parserAssertFile, err := os.Create(t.ParserAssert.File)
			if err != nil {
				return err
			}

			parserAssertFile.Close()
		}

		assertFileStat, err := os.Stat(t.ParserAssert.File)
		if err != nil {
			return fmt.Errorf("error while stats '%s': %w", t.ParserAssert.File, err)
		}

		if assertFileStat.Size() == 0 {
			assertData, err := t.ParserAssert.AutoGenFromFile(t.ParserResultFile)
			if err != nil {
				return fmt.Errorf("couldn't generate assertion: %w", err)
			}

			t.ParserAssert.AutoGenAssertData = assertData
			t.ParserAssert.AutoGenAssert = true
		} else {
			if err := t.ParserAssert.AssertFile(t.ParserResultFile); err != nil {
				// TODO: no error - should not prevent running the other tests
				return fmt.Errorf("unable to run assertion on file '%s': %w", t.ParserResultFile, err)
			}
		}
	}

View on GitHub (pinned to 909b515798)

Solutions

  1. Create the missing parser_assert.yaml in the hubtest directory (even empty, to trigger autogen)
  2. Check the test config/paths so ParserAssert.File points to the right file
  3. Fix filesystem permissions on the test directory

Example fix

// before: assert file missing
tests/test01/parser_assert.yaml   # absent
// after
touch tests/test01/parser_assert.yaml && go run ./cmd/crowdsec -test "test01" -auto-gen-only
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(filepath.Join(testDir, "parser_assert.yaml")); os.IsNotExist(err) { t.Fatalf("parser_assert.yaml missing in %s", testDir) }

Try / catch

if err := t.Run(ctx); err != nil && strings.Contains(err.Error(), "error while stats") { /* create or fix assert file, rerun */ }

Prevention

When it happens

Trigger: RunWithLogFile, when IgnoreParsers is false, calls os.Stat(t.ParserAssert.File); the file does not exist because the test directory lacks parser_assert.yaml, or the path is wrong.

Common situations: New hubtest created without a parser_assert file and without -auto-gen flow; assert file renamed or placed in a wrong directory; permissions problem on the test dir.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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