{"record":{"id":"98330e94f8a99d3d","repo":"crowdsecurity/crowdsec","slug":"no-scenarios-in-hub-index","errorCode":null,"errorMessage":"no scenarios in hub index","messagePattern":"no scenarios in hub index","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/coverage.go","lineNumber":178,"sourceCode":"\n\t\t\t\tif capturedParserName == parserNameOnly+\"-logs\" {\n\t\t\t\t\tcoverage[idx].TestsCount++\n\t\t\t\t\tcoverage[idx].PresentIn[assert] = true\n\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfile.Close()\n\t}\n\n\treturn coverage, nil\n}\n\nfunc (h *HubTest) GetScenariosCoverage(hubDir string) ([]Coverage, error) {\n\tif len(h.HubIndex.GetItemMap(cwhub.SCENARIOS)) == 0 {\n\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)","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/coverage.go#L160-L196","documentation":"Raised by GetScenariosCoverage when the loaded hub index contains no scenario items, so scenario coverage cannot be computed — the hub index is empty or wasn't refreshed before running hubtest coverage.","triggerScenarios":"Calling HubTest.GetScenariosCoverage(hubDir) after loading a hub index with no scenarios — stale index or hub directory lacking the scenarios collection.","commonSituations":"Test environments pointed at a minimal/custom hub without scenarios; hub index file truncated or from a stripped-down fork.","solutions":["Refresh the hub index ('cscli hub update') so scenarios are indexed","Point the test harness at a complete crowdsec hub checkout","Guard the call: skip scenario coverage if the index has no scenarios"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if len(h.HubIndex.GetItemMap(cwhub.SCENARIOS)) == 0 { return errors.New(\"hub index has no scenarios; run hub update\") }","typeGuard":null,"tryCatchPattern":"if _, err := h.GetScenariosCoverage(hubDir); err != nil { log.Fatalf(\"scenario coverage unavailable: %v\", err) }","preventionTips":["Update the hub index before scenario coverage runs","Use a full crowdsec hub, not a stripped-down fork","Assert non-empty scenario map in test setup"],"tags":["go","hub","scenarios","testing"],"backgroundTag":"empty-result-set","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}