{"record":{"id":"c8ae7f228fdb1f9a","repo":"crowdsecurity/crowdsec","slug":"loading-parser-dump-file-w","errorCode":null,"errorMessage":"loading parser dump file: %w","messagePattern":"loading parser dump file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/parser_assert.go","lineNumber":65,"sourceCode":"\n\treturn ParserAssert\n}\n\nfunc (p *ParserAssert) AutoGenFromFile(filename string) (string, error) {\n\terr := p.LoadTest(filename)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tret := p.AutoGenParserAssert()\n\n\treturn ret, nil\n}\n\nfunc (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)","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/parser_assert.go#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nassert := hubtest.NewParserAssert(\"./tests/syslog-logs.yaml\") // wrong file\n// after\nassert := hubtest.NewParserAssert(\"./tests/syslog-logs.dump\")\nif err := assert.LoadTest(\"./tests/syslog-logs.dump\"); err != nil {\n\tt.Fatalf(\"regenerate dump first: %v\", err)\n}","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(dumpFile); err != nil {\n\treturn fmt.Errorf(\"dump %s missing; run the parser test first\", dumpFile)\n}\nb, err := os.ReadFile(dumpFile)\nif err == nil && !json.Valid(b) {\n\treturn fmt.Errorf(\"dump %s is not valid JSON; regenerate it\", dumpFile)\n}","typeGuard":null,"tryCatchPattern":"p := hubtest.NewParserAssert(dumpFile)\nif err := p.LoadTest(dumpFile); err != nil {\n\tvar pathErr *fs.PathError\n\tif errors.As(err, &pathErr) {\n\t\t// dump missing: generate it via cscli hubtest run\n\t}\n\treturn err\n}","preventionTips":["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."],"tags":["hubtest","json","dump-file","test-data"],"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-14T00:17:10.932Z"}