crowdsecurity/crowdsec · error

while loading

Error message

while loading %s: %w

What it means

LoadAllTests walks the hub test folder and, for each subdirectory, calls LoadTestItem. Any failure from loading a single test item is wrapped as 'while loading <name>: %w' so the report identifies which test directory failed to load. LoadAllTests aborts on the first failing item rather than continuing with the rest.

Solutions

  1. Look at the wrapped inner error in the message to see whether it is a read or a YAML parse failure, then fix that file.
  2. Fix the YAML syntax in the named test directory's config.yaml (validate with `yamllint` or `python -c 'import yaml,sys;yaml.safe_load(open(sys.argv[1]))' <file>`).
  3. Restore the missing config.yaml (e.g. `git checkout -- tests/<name>/config.yaml`) if it was deleted or not copied.
  4. Remove or fix any stray directory under the tests folder that is not a valid hub test item.

Example fix

null
Defensive patterns

Strategy: validation

Validate before calling

entries, _ := os.ReadDir(testsFolder)
for _, e := range entries {
    if !e.IsDir() { continue }
    if _, err := os.Stat(filepath.Join(testsFolder, e.Name(), "config.yaml")); err != nil {
        return fmt.Errorf("test dir %s has no config.yaml", e.Name())
    }
}

Try / catch

err := h.LoadAllTests(ctx)
if err != nil {
    var wrapped interface{ Unwrap() error }
    if errors.As(err, &inner) { log.Printf("bad test: %v", inner) }
    return err
}

Prevention

When it happens

Trigger: LoadAllTests encounters a test directory whose config.yaml is missing, unreadable, or contains invalid YAML, causing LoadTestItem (and thus NewTest) to return an error.

Common situations: A partially copied or checked-out hub test directory; a test folder missing its config file; hand-edited test YAML with syntax errors; permissions on the tests directory; a stray non-test directory inside the tests folder that lacks a config.

Related errors


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

Appendix: source

Thrown at pkg/hubtest/hubtest.go:222

	if err != nil {
		return HubTestItem, err
	}

	h.Tests = append(h.Tests, testItem)

	return testItem, nil
}

func (h *HubTest) LoadAllTests() error {
	testsFolder, err := os.ReadDir(h.HubTestPath)
	if err != nil {
		return err
	}

	for _, f := range testsFolder {
		if f.IsDir() {
			if _, err := h.LoadTestItem(f.Name()); err != nil {
				return fmt.Errorf("while loading %s: %w", f.Name(), err)
			}
		}
	}

	return nil
}

View on GitHub (pinned to 909b515798)