crowdsecurity/crowdsec · error

while find parser asserts: %w

Error message

while find parser asserts: %w

What it means

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.

Source

Thrown at pkg/hubtest/coverage.go:110

		return nil, errors.New("no parsers in hub index")
	}

	// populate from hub, iterate in alphabetical order
	pkeys := maptools.SortedKeys(h.HubIndex.GetItemMap(cwhub.PARSERS))
	coverage := make([]Coverage, len(pkeys))

	for i, name := range pkeys {
		coverage[i] = Coverage{
			Name:       name,
			TestsCount: 0,
			PresentIn:  make(map[string]bool),
		}
	}

	// parser the expressions a-la-oneagain
	passerts, err := filepath.Glob(filepath.Join(hubDir, ".tests", "*", "parser.assert"))
	if err != nil {
		return nil, fmt.Errorf("while find parser asserts: %w", err)
	}

	for _, assert := range passerts {
		file, err := os.Open(assert)
		if err != nil {
			return nil, fmt.Errorf("while reading %s: %w", assert, err)
		}

		scanner := bufio.NewScanner(file)
		for scanner.Scan() {
			line := scanner.Text()
			log.Debugf("assert line : %s", line)

			match := parserResultRE.FindStringSubmatch(line)
			if len(match) == 0 {
				log.Debugf("%s doesn't match", line)
				continue
			}

View on GitHub (pinned to 909b515798)

Solutions

  1. Inspect the hubDir string for glob metacharacters ('[', ']', '?', '*') and rename the directory to avoid them
  2. Escape metacharacters with filepath.Escape before the path is joined into the glob pattern
  3. Pass a plain, metacharacter-free absolute path as hubDir

Example fix

// before
hubDir := "/tmp/dir[0]"
GetParsersCoverage(hubDir, ...)
// after
hubDir := filepath.Escape("/tmp/dir[0]")
GetParsersCoverage(hubDir, ...)
Defensive patterns

Strategy: validation

Validate before calling

if strings.ContainsAny(hubDir, "[]*?") {
    hubDir = filepath.Escape(hubDir)
}
if _, err := filepath.Glob(filepath.Join(hubDir, ".tests", "*", "parser.assert")); err != nil {
    return err
}

Try / catch

cov, err := hubtest.GetParsersCoverage(hubDir, ...)
if err != nil {
    if strings.Contains(err.Error(), "syntax error in pattern") { /* sanitize hubDir and retry */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/813d528ef2e680f7. Report an issue: GitHub.