crowdsecurity/crowdsec · error
couldn't generate assertion: %w
Error message
couldn't generate assertion: %w
What it means
When the parser assert file exists but is empty (size 0), hubtest auto-generates assertions from the parser results dump (ParserResultFile). This error wraps any failure of AutoGenFromFile, typically because the results file is missing or unreadable.
Source
Thrown at pkg/hubtest/hubtest_item.go:536
_, 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)
}
}
}
// assert scenarios
nbScenario := 0
for _, scenario := range t.Config.Scenarios {
if scenario == "" {
continueView on GitHub (pinned to 909b515798)
Solutions
- Run the hubtest with auto-generation enabled to populate the assert file from a successful parse run
- Ensure the crowdsec parse step completed and wrote t.ParserResultFile
- Check permissions and path of the results directory
Example fix
// before: empty parser_assert.yaml committed // after: generate it ./tests/crowdsec -c tests/test01/runtime.yaml -dump-data tests/test01/results && regenerate asserts
Defensive patterns
Strategy: validation
Validate before calling
if st, err := os.Stat(parserResultFile); err != nil || st.Size() == 0 { t.Fatalf("parser results missing/empty at %s", parserResultFile) } Try / catch
if err := t.Run(ctx); err != nil && strings.Contains(err.Error(), "couldn't generate assertion") { /* ensure parse ran and dump exists, retry */ } Prevention
- Never commit empty assert files without an autogen step in CI
- Ensure the parse step completes before assertion autogen
- Keep results dir intact during the test run
When it happens
Trigger: RunWithLogFile: parser_assert.yaml is 0 bytes and ParserAssert.AutoGenFromFile(t.ParserResultFile) fails — e.g. results dump absent because the parse step produced nothing or dump-data target was removed.
Common situations: Empty assert file committed without ever running autogen; results directory cleaned between the parse and assert steps; parse run silently produced no output so the results file was never created.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- error while stats '%s': %w
- unable to run assertion on file '%s': %w
- couldn't generate assertion: %w
- ErrNucleiRunFail
- can't find crowdsec binary: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/28c77f1f9c2b1fb7.
Report an issue: GitHub.