crowdsecurity/crowdsec · error
unable to load parser dump file '%s': %w
Error message
unable to load parser dump file '%s': %w
What it means
AssertFile opens the assertion's own result file and then loads the expected test dump via LoadTest; when loading the dump fails it wraps the error with the dump path. Functionally the same family as the LoadTest error but raised from AssertFile, so the failing path is the testFile argument, making it clear which dump was bad.
Source
Thrown at pkg/hubtest/parser_assert.go:80
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)
scanner.Split(bufio.ScanLines)
nbLine := 0
for scanner.Scan() {
nbLine++
if scanner.Text() == "" {
continue
}
ok, err := p.Run(scanner.Text())
if err != nil {
return fmt.Errorf("unable to run assert '%s': %w", scanner.Text(), err)
}View on GitHub (pinned to 909b515798)
Solutions
- Regenerate the dump by running the parser test (cscli hubtest run <test>) before asserting.
- Check the testFile path passed to AssertFile resolves to an existing .dump file.
- Validate the JSON: `jq . <testFile>`; if broken, delete and regenerate the dump.
- Regenerate dumps with the current crowdsec version after upgrading.
Example fix
// before
assert.LoadTest(testFile) // testFile may not exist yet
// after
if _, err := os.Stat(testFile); err != nil {
t.Skipf("dump %s not generated yet, run the parser test first", testFile)
}
assert.LoadTest(testFile) Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(testFile); err != nil {
return fmt.Errorf("dump %s not found; generate with 'cscli hubtest run'", testFile)
} Try / catch
if err := p.AssertFile(); err != nil {
if strings.Contains(err.Error(), "unable to load parser dump file") {
// regenerate the dump at the path named in the error, then retry
}
return err
} Prevention
- Run the dump-producing step before assertions in your test pipeline.
- Avoid passing hand-built or truncated dump paths.
- Treat the dump path in the error message as the authoritative file to fix.
- Regenerate all dumps when bumping crowdsec versions.
When it happens
Trigger: Calling AssertFile (via RunWithLogFile) with a testFile path whose dump cannot be loaded: missing file, invalid JSON, or format mismatch — after the assertion file itself opened fine.
Common situations: Passing a wrong/relative testFile path in the test suite; dump never generated for this test; dump truncated by an interrupted earlier run; format drift after a crowdsec upgrade.
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
- loading parser dump file: %w
- failed to open
- failed to open
- no header in message, skipping
- no source user in header message, skipping
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/cf4721fa6b97b879.
Report an issue: GitHub.