{"record":{"id":"cf4721fa6b97b879","repo":"crowdsecurity/crowdsec","slug":"unable-to-load-parser-dump-file-s-w","errorCode":null,"errorMessage":"unable to load parser dump file '%s': %w","messagePattern":"unable to load parser dump file '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/parser_assert.go","lineNumber":80,"sourceCode":"func (p *ParserAssert) LoadTest(filename string) error {\n\tparserDump, err := dumps.LoadParserDump(filename)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"loading parser dump file: %w\", err)\n\t}\n\n\tp.TestData = parserDump\n\n\treturn nil\n}\n\nfunc (p *ParserAssert) AssertFile(testFile string) error {\n\tfile, err := os.Open(p.File)\n\tif err != nil {\n\t\treturn errors.New(\"failed to open\")\n\t}\n\n\tif err := p.LoadTest(testFile); err != nil {\n\t\treturn fmt.Errorf(\"unable to load parser dump file '%s': %w\", testFile, err)\n\t}\n\n\tscanner := bufio.NewScanner(file)\n\tscanner.Split(bufio.ScanLines)\n\n\tnbLine := 0\n\n\tfor scanner.Scan() {\n\t\tnbLine++\n\n\t\tif scanner.Text() == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tok, err := p.Run(scanner.Text())\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to run assert '%s': %w\", scanner.Text(), err)\n\t\t}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/parser_assert.go#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nassert.LoadTest(testFile) // testFile may not exist yet\n// after\nif _, err := os.Stat(testFile); err != nil {\n\tt.Skipf(\"dump %s not generated yet, run the parser test first\", testFile)\n}\nassert.LoadTest(testFile)","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(testFile); err != nil {\n\treturn fmt.Errorf(\"dump %s not found; generate with 'cscli hubtest run'\", testFile)\n}","typeGuard":null,"tryCatchPattern":"if err := p.AssertFile(); err != nil {\n\tif strings.Contains(err.Error(), \"unable to load parser dump file\") {\n\t\t// regenerate the dump at the path named in the error, then retry\n\t}\n\treturn err\n}","preventionTips":["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."],"tags":["hubtest","json","dump-file","assertions"],"backgroundTag":"json-parse-error","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}