{"record":{"id":"2fbd19ad8d5fb62e","repo":"crowdsecurity/crowdsec","slug":"while-loading-s-w","errorCode":null,"errorMessage":"while loading %s: %w","messagePattern":"while loading (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest.go","lineNumber":222,"sourceCode":"\tif err != nil {\n\t\treturn HubTestItem, err\n\t}\n\n\th.Tests = append(h.Tests, testItem)\n\n\treturn testItem, nil\n}\n\nfunc (h *HubTest) LoadAllTests() error {\n\ttestsFolder, err := os.ReadDir(h.HubTestPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfor _, f := range testsFolder {\n\t\tif f.IsDir() {\n\t\t\tif _, err := h.LoadTestItem(f.Name()); err != nil {\n\t\t\t\treturn fmt.Errorf(\"while loading %s: %w\", f.Name(), err)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":204,"sourceCodeEnd":229,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest.go#L204-L229","documentation":"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.","triggerScenarios":"LoadAllTests encounters a test directory whose config.yaml is missing, unreadable, or contains invalid YAML, causing LoadTestItem (and thus NewTest) to return an error.","commonSituations":"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.","solutions":["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.","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>`).","Restore the missing config.yaml (e.g. `git checkout -- tests/<name>/config.yaml`) if it was deleted or not copied.","Remove or fix any stray directory under the tests folder that is not a valid hub test item."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"entries, _ := os.ReadDir(testsFolder)\nfor _, e := range entries {\n    if !e.IsDir() { continue }\n    if _, err := os.Stat(filepath.Join(testsFolder, e.Name(), \"config.yaml\")); err != nil {\n        return fmt.Errorf(\"test dir %s has no config.yaml\", e.Name())\n    }\n}","typeGuard":null,"tryCatchPattern":"err := h.LoadAllTests(ctx)\nif err != nil {\n    var wrapped interface{ Unwrap() error }\n    if errors.As(err, &inner) { log.Printf(\"bad test: %v\", inner) }\n    return err\n}","preventionTips":["Keep test directories complete: every test dir must contain config.yaml.","Validate test YAML in CI before running LoadAllTests.","Clean stray directories out of the tests folder."],"tags":["hubtest","yaml","loading"],"backgroundTag":"yaml-parse-error","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"}