{"record":{"id":"f6ff0027929f1fbf","repo":"crowdsecurity/crowdsec","slug":"failed-to-open","errorCode":null,"errorMessage":"failed to open","messagePattern":"failed to open","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/parser_assert.go","lineNumber":76,"sourceCode":"\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)\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","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/parser_assert.go#L58-L94","documentation":"ParserAssert.AssertFile opens the parser dump file configured at p.File and immediately returns the bare string error \"failed to open\" if os.Open fails, discarding the OS error. It signals the assertion harness could not read the dump file it is supposed to parse, so no assertions can be evaluated.","triggerScenarios":"Calling ParserAssert.AssertFile (via RunWithLogFile) when p.File does not exist, has wrong permissions, or is a directory — any os.Open failure on the configured dump file path.","commonSituations":"Hubtest run in a fresh checkout where the parser dump was never generated (tests never ran before the assert step); wrong path in the test config; file removed by a clean step; running as a user without read permission on /tmp artifacts.","solutions":["Generate the parser dump first by running the test data through the parser before asserting","Check that the dump file path (p.File) exists: ls <path> and correct the path in the test config","Fix file permissions on the dump file/directory","Note the error loses the OS detail: temporarily add %w wrapping of the os.Open error to see the exact cause","Confirm RunWithLogFile passes the correct testFile so LoadTest is pointed at the right dump"],"exampleFix":"// before\nfile, err := os.Open(p.File)\nif err != nil {\n    return errors.New(\"failed to open\")\n}\n// after\nfile, err := os.Open(p.File)\nif err != nil {\n    return fmt.Errorf(\"failed to open parser dump '%s': %w\", p.File, err)\n}","handlingStrategy":"validation","validationCode":"func assertDumpReadable(path string) error {\n    fi, err := os.Stat(path)\n    if err != nil { return fmt.Errorf(\"dump file missing: %w\", err) }\n    if fi.IsDir() { return fmt.Errorf(\"%s is a directory\", path) }\n    f, err := os.Open(path); if err != nil { return err }; return f.Close()\n}","typeGuard":null,"tryCatchPattern":"if err := p.AssertFile(testFile); err != nil {\n    if strings.Contains(err.Error(), \"failed to open\") {\n        log.Printf(\"check parser dump path %q exists and is readable\", p.File)\n    }\n    return err\n}","preventionTips":["Always run the parser stage that generates the dump before the assert stage","Keep dump paths relative to the hubtest item's directory, not absolute /tmp paths","Wrap the os.Open error with %w so future failures show the real cause","Check file permissions when running hubtest under CI users"],"tags":["file-io","hubtest","assertions"],"backgroundTag":"file-open-failed","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"}