{"record":{"id":"42fcb5ee6ae74de7","repo":"crowdsecurity/crowdsec","slug":"no-appsec-rules-in-hub-index","errorCode":null,"errorMessage":"no appsec rules in hub index","messagePattern":"no appsec rules in hub index","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/coverage.go","lineNumber":28,"sourceCode":"\n\tlog \"github.com/sirupsen/logrus\"\n\t\"gopkg.in/yaml.v3\"\n\n\t\"github.com/crowdsecurity/go-cs-lib/maptools\"\n\n\t\"github.com/crowdsecurity/crowdsec/pkg/appsec/appsec_rule\"\n\t\"github.com/crowdsecurity/crowdsec/pkg/cwhub\"\n)\n\ntype Coverage struct {\n\tName       string\n\tTestsCount int\n\tPresentIn  map[string]bool // poorman's set\n}\n\nfunc (h *HubTest) GetAppsecCoverage(hubDir string) ([]Coverage, error) {\n\tif len(h.HubIndex.GetItemMap(cwhub.APPSEC_RULES)) == 0 {\n\t\treturn nil, errors.New(\"no appsec rules in hub index\")\n\t}\n\n\t// populate from hub, iterate in alphabetical order\n\tpkeys := maptools.SortedKeys(h.HubIndex.GetItemMap(cwhub.APPSEC_RULES))\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\tappsecTestConfigs, err := filepath.Glob(filepath.Join(hubDir, \".appsec-tests\", \"*\", \"config.yaml\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"while find appsec-tests config: %w\", err)","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/coverage.go#L10-L46","documentation":"GetAppsecCoverage in pkg/hubtest/coverage.go returns this error when the hub index contains zero items of type APPSEC_RULES. Coverage enumeration cannot proceed without at least one appsec rule item to iterate over.","triggerScenarios":"Calling HubTest.GetAppsecCoverage(hubDir) after loading an index with no appsec-rules entries — e.g. an old hub index file predating appsec rules, or hub not updated.","commonSituations":"Running hub test/coverage tooling against a stale local hub clone; hub index not updated (cscli hub update) on an installation from before the appsec feature existed.","solutions":["Run 'cscli hub update' to refresh the hub index so appsec rules are present","Verify the hub directory contains an index.json with appsec-rules entries","Skip appsec coverage when testing against a legacy hub without appsec rules"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if len(h.HubIndex.GetItemMap(cwhub.APPSEC_RULES)) == 0 { skipAppsecCoverage = true }","typeGuard":null,"tryCatchPattern":"coverage, err := h.GetAppsecCoverage(hubDir)\nif err != nil { log.Warn(err); return }","preventionTips":["Run 'cscli hub update' before hub test/coverage tooling","Verify the hub index contains appsec-rules entries","Skip appsec coverage gracefully on legacy hubs"],"tags":["go","hub","appsec","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"}