{"record":{"id":"813d528ef2e680f7","repo":"crowdsecurity/crowdsec","slug":"while-find-parser-asserts-w","errorCode":null,"errorMessage":"while find parser asserts: %w","messagePattern":"while find parser asserts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/coverage.go","lineNumber":110,"sourceCode":"\t\treturn nil, errors.New(\"no parsers in hub index\")\n\t}\n\n\t// populate from hub, iterate in alphabetical order\n\tpkeys := maptools.SortedKeys(h.HubIndex.GetItemMap(cwhub.PARSERS))\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\", \"*\", \"parser.assert\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"while find parser 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\n\t\t\tmatch := parserResultRE.FindStringSubmatch(line)\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":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/coverage.go#L92-L128","documentation":"GetParsersCoverage enumerates parser assertion files with filepath.Glob over <hubDir>/.tests/*/parser.assert. If the Glob pattern itself is malformed (ErrBadPattern), the function returns 'while find parser asserts: <err>'. This is a pattern-synthesis failure, not a missing-file problem.","triggerScenarios":"Calling GetParsersCoverage(hubDir, ...) where hubDir contains characters invalid in a filepath.Match pattern, or the pattern construction produces a syntax error — practically only when hubDir contains unbalanced '[' or other glob metacharacters.","commonSituations":"Hub checked out into a path containing glob metacharacters like '[' (common in test sandbox dirs with bracketed names); passing a hubDir that was already partially glob-expanded.","solutions":["Inspect the hubDir string for glob metacharacters ('[', ']', '?', '*') and rename the directory to avoid them","Escape metacharacters with filepath.Escape before the path is joined into the glob pattern","Pass a plain, metacharacter-free absolute path as hubDir"],"exampleFix":"// before\nhubDir := \"/tmp/dir[0]\"\nGetParsersCoverage(hubDir, ...)\n// after\nhubDir := filepath.Escape(\"/tmp/dir[0]\")\nGetParsersCoverage(hubDir, ...)","handlingStrategy":"validation","validationCode":"if strings.ContainsAny(hubDir, \"[]*?\") {\n    hubDir = filepath.Escape(hubDir)\n}\nif _, err := filepath.Glob(filepath.Join(hubDir, \".tests\", \"*\", \"parser.assert\")); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"cov, err := hubtest.GetParsersCoverage(hubDir, ...)\nif err != nil {\n    if strings.Contains(err.Error(), \"syntax error in pattern\") { /* sanitize hubDir and retry */ }\n}","preventionTips":["Avoid glob metacharacters in directory names for hub checkouts","Use filepath.Escape when a path may contain metacharacters","Test hubtest in paths built by CI which sometimes contain brackets"],"tags":["glob","filesystem","hubtest","parsers"],"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"}