{"record":{"id":"6cc0cec71b9ce7e1","repo":"crowdsecurity/crowdsec","slug":"error-while-stats-s-w","errorCode":null,"errorMessage":"error while stats '%s': %w","messagePattern":"error while stats '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":530,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"fail to run '%s' for test '%s': %w\", crowdsecCmd.String(), t.Name, err)\n\t}\n\n\t// assert parsers\n\tif !t.Config.IgnoreParsers {\n\t\t_, err := os.Stat(t.ParserAssert.File)\n\t\tif os.IsNotExist(err) {\n\t\t\tparserAssertFile, err := os.Create(t.ParserAssert.File)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tparserAssertFile.Close()\n\t\t}\n\n\t\tassertFileStat, err := os.Stat(t.ParserAssert.File)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error while stats '%s': %w\", t.ParserAssert.File, err)\n\t\t}\n\n\t\tif assertFileStat.Size() == 0 {\n\t\t\tassertData, err := t.ParserAssert.AutoGenFromFile(t.ParserResultFile)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"couldn't generate assertion: %w\", err)\n\t\t\t}\n\n\t\t\tt.ParserAssert.AutoGenAssertData = assertData\n\t\t\tt.ParserAssert.AutoGenAssert = true\n\t\t} else {\n\t\t\tif err := t.ParserAssert.AssertFile(t.ParserResultFile); err != nil {\n\t\t\t\t// TODO: no error - should not prevent running the other tests\n\t\t\t\treturn fmt.Errorf(\"unable to run assertion on file '%s': %w\", t.ParserResultFile, err)\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L512-L548","documentation":"After the parse run, hubtest stats the parser assertion file (parser_assert.yaml) to decide between autogeneration and assertion checking. If os.Stat fails (file missing or unreadable) the run aborts with this wrapped error.","triggerScenarios":"RunWithLogFile, when IgnoreParsers is false, calls os.Stat(t.ParserAssert.File); the file does not exist because the test directory lacks parser_assert.yaml, or the path is wrong.","commonSituations":"New hubtest created without a parser_assert file and without -auto-gen flow; assert file renamed or placed in a wrong directory; permissions problem on the test dir.","solutions":["Create the missing parser_assert.yaml in the hubtest directory (even empty, to trigger autogen)","Check the test config/paths so ParserAssert.File points to the right file","Fix filesystem permissions on the test directory"],"exampleFix":"// before: assert file missing\ntests/test01/parser_assert.yaml   # absent\n// after\ntouch tests/test01/parser_assert.yaml && go run ./cmd/crowdsec -test \"test01\" -auto-gen-only","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(filepath.Join(testDir, \"parser_assert.yaml\")); os.IsNotExist(err) { t.Fatalf(\"parser_assert.yaml missing in %s\", testDir) }","typeGuard":null,"tryCatchPattern":"if err := t.Run(ctx); err != nil && strings.Contains(err.Error(), \"error while stats\") { /* create or fix assert file, rerun */ }","preventionTips":["Scaffold new hubtests with both assert files present (even empty for autogen)","Check test dir naming conventions against expected paths","Run in CI with a user owning the test tree"],"tags":["hubtest","stat-failed","assertion","testing"],"backgroundTag":"file-not-found","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"}