crowdsecurity/crowdsec · error

unable to run assertion on file '%s': %w

Error message

unable to run assertion on file '%s': %w

What it means

When a non-empty parser_assert.yaml exists, hubtest runs the assertions against the parser results file via ParserAssert.AssertFile. Failure of that evaluation aborts the test with this error, even though a TODO notes it arguably should not block other tests.

Source

Thrown at pkg/hubtest/hubtest_item.go:544

		}

		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)
			}
		}
	}

	// assert scenarios
	nbScenario := 0

	for _, scenario := range t.Config.Scenarios {
		if scenario == "" {
			continue
		}

		nbScenario++
	}

	if nbScenario > 0 {
		_, err := os.Stat(t.ScenarioAssert.File)
		if os.IsNotExist(err) {

View on GitHub (pinned to 909b515798)

Solutions

  1. Validate the YAML and expr expressions in parser_assert.yaml
  2. Regenerate the assert file via autogen to get syntactically correct assertions
  3. Verify the results file exists and matches the expected dump format

Example fix

// before (invalid expr)
- expression: 'LogPart.name == '  # unbalanced quotes
// after
- expression: LogPart["s01-parse"].name == "sshd-scraper"
Defensive patterns

Strategy: validation

Validate before calling

if _, err := yaml.Marshal(parserAssertContent); err != nil { t.Fatalf("invalid parser_assert yaml: %v", err) }

Try / catch

if err := t.Run(ctx); err != nil && strings.Contains(err.Error(), "unable to run assertion") { /* fix expr syntax in parser_assert.yaml */ }

Prevention

When it happens

Trigger: RunWithLogFile: t.ParserAssert.AssertFile(t.ParserResultFile) returns an error — malformed YAML in the assert file, expression evaluation failure (expr syntax error), or the results file is missing/unparseable.

Common situations: Hand-edited parser_assert.yaml with invalid expr syntax or wrong YAML structure; results file format changed after a version bump; typo in assert field names.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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