{"record":{"id":"e1773c9dc0b36c9c","repo":"crowdsecurity/crowdsec","slug":"failed-to-open-e1773c","errorCode":null,"errorMessage":"failed to open","messagePattern":"failed to open","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/scenario_assert.go","lineNumber":83,"sourceCode":"\n\ts.TestData = bucketDump\n\n\tif bucketpour != \"\" {\n\t\tpourDump, err := dumps.LoadBucketPourDump(bucketpour)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"loading bucket pour dump file '%s': %w\", filename, err)\n\t\t}\n\n\t\ts.PourData = pourDump\n\t}\n\n\treturn nil\n}\n\nfunc (s *ScenarioAssert) AssertFile(testFile string) error {\n\tfile, err := os.Open(s.File)\n\tif err != nil {\n\t\treturn errors.New(\"failed to open\")\n\t}\n\n\tif err := s.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":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/scenario_assert.go#L65-L101","documentation":"ScenarioAssert.AssertFile opens the scenario dump file at s.File and returns the bare error \"failed to open\" if os.Open fails, discarding the OS cause. It means the scenario assertion harness cannot read its dump file, so scenario-level assertions cannot run.","triggerScenarios":"Calling ScenarioAssert.AssertFile (via RunWithLogFile) when s.File is missing, unreadable, or not a regular file — any os.Open failure.","commonSituations":"Scenario dump never produced because the earlier test stage failed or was skipped; wrong output_dir configured for the scenario test; stale absolute paths after moving the test tree; permission issues on generated artifacts.","solutions":["Run the scenario test stage that generates the dump file before the assert stage","Verify s.File exists and fix the path in the scenario test config","Fix permissions on the dump file and its parent directory","Wrap the os.Open error with %w (as in the suggested fix) to surface the true cause","Re-run hubtest with a clean output_dir to regenerate the dump at the expected location"],"exampleFix":"// before\nfile, err := os.Open(s.File)\nif err != nil {\n    return errors.New(\"failed to open\")\n}\n// after\nfile, err := os.Open(s.File)\nif err != nil {\n    return fmt.Errorf(\"failed to open scenario dump '%s': %w\", s.File, err)\n}","handlingStrategy":"validation","validationCode":"func assertDumpReadable(path string) error {\n    fi, err := os.Stat(path)\n    if err != nil { return fmt.Errorf(\"scenario dump 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 := s.AssertFile(testFile); err != nil {\n    if strings.Contains(err.Error(), \"failed to open\") {\n        log.Printf(\"check scenario dump path %q exists and is readable\", s.File)\n    }\n    return err\n}","preventionTips":["Generate the scenario dump before asserting (run the test stage in order)","Verify output_dir in the scenario test config matches where dumps are written","Clean and regenerate dump files rather than reusing stale ones across refactors","Fix permissions on generated artifacts before CI assert steps"],"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-14T00:17:10.932Z"}