{"record":{"id":"b8d9274078e8a5bb","repo":"crowdsecurity/crowdsec","slug":"unable-to-run-assertion-on-file-s-w","errorCode":null,"errorMessage":"unable to run assertion on file '%s': %w","messagePattern":"unable to run assertion on file '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":544,"sourceCode":"\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\n\t// assert scenarios\n\tnbScenario := 0\n\n\tfor _, scenario := range t.Config.Scenarios {\n\t\tif scenario == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tnbScenario++\n\t}\n\n\tif nbScenario > 0 {\n\t\t_, err := os.Stat(t.ScenarioAssert.File)\n\t\tif os.IsNotExist(err) {","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L526-L562","documentation":"When a non-empty parser_assert.yaml exists, hubtest runs the assertions against the parser results file via ParserAssert.AssertFile. Failure of that evaluation aborts the test with this error, even though a TODO notes it arguably should not block other tests.","triggerScenarios":"RunWithLogFile: t.ParserAssert.AssertFile(t.ParserResultFile) returns an error — malformed YAML in the assert file, expression evaluation failure (expr syntax error), or the results file is missing/unparseable.","commonSituations":"Hand-edited parser_assert.yaml with invalid expr syntax or wrong YAML structure; results file format changed after a version bump; typo in assert field names.","solutions":["Validate the YAML and expr expressions in parser_assert.yaml","Regenerate the assert file via autogen to get syntactically correct assertions","Verify the results file exists and matches the expected dump format"],"exampleFix":"// before (invalid expr)\n- expression: 'LogPart.name == '  # unbalanced quotes\n// after\n- expression: LogPart[\"s01-parse\"].name == \"sshd-scraper\"","handlingStrategy":"validation","validationCode":"if _, err := yaml.Marshal(parserAssertContent); err != nil { t.Fatalf(\"invalid parser_assert yaml: %v\", err) }","typeGuard":null,"tryCatchPattern":"if err := t.Run(ctx); err != nil && strings.Contains(err.Error(), \"unable to run assertion\") { /* fix expr syntax in parser_assert.yaml */ }","preventionTips":["Lint expr expressions in assert files","Regenerate asserts via autogen after parser field changes","Validate YAML structure after hand edits"],"tags":["hubtest","assertion","expr","yaml","testing"],"backgroundTag":"schema-validation-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"}