{"record":{"id":"7bed31bf61afe5b0","repo":"crowdsecurity/crowdsec","slug":"while-find-scenario-asserts-w","errorCode":null,"errorMessage":"while find scenario asserts: %w","messagePattern":"while find scenario asserts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/coverage.go","lineNumber":196,"sourceCode":"\t\treturn nil, errors.New(\"no scenarios in hub index\")\n\t}\n\n\t// populate from hub, iterate in alphabetical order\n\tpkeys := maptools.SortedKeys(h.HubIndex.GetItemMap(cwhub.SCENARIOS))\n\tcoverage := make([]Coverage, len(pkeys))\n\n\tfor i, name := range pkeys {\n\t\tcoverage[i] = Coverage{\n\t\t\tName:       name,\n\t\t\tTestsCount: 0,\n\t\t\tPresentIn:  make(map[string]bool),\n\t\t}\n\t}\n\n\t// parser the expressions a-la-oneagain\n\tpasserts, err := filepath.Glob(filepath.Join(hubDir, \".tests\", \"*\", \"scenario.assert\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"while find scenario asserts: %w\", err)\n\t}\n\n\tfor _, assert := range passerts {\n\t\tfile, err := os.Open(assert)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"while reading %s: %w\", assert, err)\n\t\t}\n\n\t\tscanner := bufio.NewScanner(file)\n\t\tfor scanner.Scan() {\n\t\t\tline := scanner.Text()\n\t\t\tlog.Debugf(\"assert line : %s\", line)\n\t\t\tmatch := scenarioResultRE.FindStringSubmatch(line)\n\n\t\t\tif len(match) == 0 {\n\t\t\t\tlog.Debugf(\"%s doesn't match\", line)\n\t\t\t\tcontinue\n\t\t\t}","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/coverage.go#L178-L214","documentation":"GetScenariosCoverage globs <hubDir>/.tests/*/scenario.assert files; a malformed glob pattern aborts with 'while find scenario asserts: <err>'. Same ErrBadPattern failure mode as the parser coverage path, applied to scenario asserts.","triggerScenarios":"Calling GetScenariosCoverage(hubDir, ...) when hubDir (or the joined pattern) contains unbalanced glob metacharacters such as '[' causing filepath.Glob to return ErrBadPattern.","commonSituations":"Hub directory path containing bracketed or wildcard characters (sandbox/test dir names like 'dir[0]'); hubDir accidentally containing a glob expression instead of a literal path.","solutions":["Remove or escape glob metacharacters in the hubDir path (filepath.Escape)","Rename the directory to one without '[', ']', '?', '*'","Pass a plain absolute literal path as hubDir"],"exampleFix":"// before\nGetScenariosCoverage(\"/tmp/hub[test]\", ...)\n// after\nGetScenariosCoverage(filepath.Escape(\"/tmp/hub[test]\"), ...)","handlingStrategy":"validation","validationCode":"if strings.ContainsAny(hubDir, \"[]*?\") {\n    hubDir = filepath.Escape(hubDir)\n}\nif _, err := filepath.Glob(filepath.Join(hubDir, \".tests\", \"*\", \"scenario.assert\")); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"cov, err := hubtest.GetScenariosCoverage(hubDir, ...)\nif err != nil {\n    if strings.Contains(err.Error(), \"syntax error in pattern\") { /* sanitize hubDir and retry */ }\n}","preventionTips":["Keep hub checkout paths free of glob metacharacters","Escape dynamic path components before globbing","Add a preflight glob check in test harnesses"],"tags":["glob","filesystem","hubtest","scenarios"],"backgroundTag":"invalid-url-format","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"}