crowdsecurity/crowdsec · error
loading parser dump file: %w
Error message
loading parser dump file: %w
What it means
ParserAssert.LoadTest loads a parser dump (the JSON output of a previous parser run) via dumps.LoadParserDump and wraps any failure. It indicates the .dump file is missing, unreadable, or not valid parser-dump JSON — so assertions cannot run against test data.
Source
Thrown at pkg/hubtest/parser_assert.go:65
return ParserAssert
}
func (p *ParserAssert) AutoGenFromFile(filename string) (string, error) {
err := p.LoadTest(filename)
if err != nil {
return "", err
}
ret := p.AutoGenParserAssert()
return ret, nil
}
func (p *ParserAssert) LoadTest(filename string) error {
parserDump, err := dumps.LoadParserDump(filename)
if err != nil {
return fmt.Errorf("loading parser dump file: %w", err)
}
p.TestData = parserDump
return nil
}
func (p *ParserAssert) AssertFile(testFile string) error {
file, err := os.Open(p.File)
if err != nil {
return errors.New("failed to open")
}
if err := p.LoadTest(testFile); err != nil {
return fmt.Errorf("unable to load parser dump file '%s': %w", testFile, err)
}
scanner := bufio.NewScanner(file)View on GitHub (pinned to 909b515798)
Solutions
- Verify the dump file exists at the given path (`ls <test>.dump`) and generate it by running the parser test first (cscli hubtest run).
- Validate the dump is well-formed JSON: `jq . <test>.dump`.
- Ensure you pass the .dump file, not the .yaml, to LoadTest/AssertFile.
- Regenerate the dump with the current crowdsec version if it comes from an older format.
Example fix
// before
assert := hubtest.NewParserAssert("./tests/syslog-logs.yaml") // wrong file
// after
assert := hubtest.NewParserAssert("./tests/syslog-logs.dump")
if err := assert.LoadTest("./tests/syslog-logs.dump"); err != nil {
t.Fatalf("regenerate dump first: %v", err)
} Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Stat(dumpFile); err != nil {
return fmt.Errorf("dump %s missing; run the parser test first", dumpFile)
}
b, err := os.ReadFile(dumpFile)
if err == nil && !json.Valid(b) {
return fmt.Errorf("dump %s is not valid JSON; regenerate it", dumpFile)
} Try / catch
p := hubtest.NewParserAssert(dumpFile)
if err := p.LoadTest(dumpFile); err != nil {
var pathErr *fs.PathError
if errors.As(err, &pathErr) {
// dump missing: generate it via cscli hubtest run
}
return err
} Prevention
- Generate dumps (cscli hubtest run) before running assertions.
- Pass the .dump file, never the .yaml, to assertion APIs.
- Validate dumps with `jq .` after manual edits.
- Regenerate dumps after crowdsec version upgrades.
When it happens
Trigger: Calling AssertFile/AutoGenFromFile with a testFile whose dump file fails to load: file doesn't exist, wrong extension/path passed, JSON malformed or produced by an incompatible dump format version.
Common situations: Running assertions before generating the dump (parser never ran); hand-editing the dump and breaking JSON; pointing AssertFile at the .yaml test config instead of the .dump file; dump produced by an older crowdsec format.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- unable to load parser dump file '%s': %w
- no header in message, skipping
- no source user in header message, skipping
- unable to serialize
- ErrNucleiRunFail
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/c8ae7f228fdb1f9a.
Report an issue: GitHub.