crowdsecurity/crowdsec · error
couldn't find custom appsec-rule '%s' in the following locat
Error message
couldn't find custom appsec-rule '%s' in the following location: %+v
What it means
installAppsecRuleCustom exhausts every directory in CustomItemsLocation without finding a file named after the requested custom appsec-rule, so the install fails. It distinguishes custom (non-hub) rules: the name was not found in the hub index nor in any custom location.
Source
Thrown at pkg/hubtest/appsecrule.go:84
return false, fmt.Errorf("unable to copy appsec-rule from '%s' to '%s': %w", customAppsecRulePath, customAppsecRuleDest, err)
}
return true, nil
}
func (t *HubTestItem) installAppsecRuleCustom(appsecrule string) error {
for _, customPath := range t.CustomItemsLocation {
found, err := t.installAppsecRuleCustomFrom(appsecrule, customPath)
if err != nil {
return err
}
if found {
return nil
}
}
return fmt.Errorf("couldn't find custom appsec-rule '%s' in the following location: %+v", appsecrule, t.CustomItemsLocation)
}
func (t *HubTestItem) installAppsecRule(name string) error {
log.Debugf("adding rule '%s'", name)
if item := t.HubIndex.GetItem(cwhub.APPSEC_RULES, name); item != nil {
return t.installAppsecRuleItem(item)
}
return t.installAppsecRuleCustom(name)
}
View on GitHub (pinned to 909b515798)
Solutions
- Confirm the file '<appsecrule>' exists in one of the CustomItemsLocation directories (paths are printed in the error)
- Fix the rule name in the test config to match the file name exactly (including .yaml extension)
- Add the rule file to the expected custom items directory used by the test
Example fix
# before: test config references 'my-custom-rule' but file missing .appsec-tests/ .tests/my-custom-rule.yaml -> references my-custom-rule (not present) # after cp my-custom-rule.yaml .tests/ # or rename to match referenced name
Defensive patterns
Strategy: validation
Validate before calling
found := false
for _, dir := range t.CustomItemsLocation {
if _, err := os.Stat(filepath.Join(dir, appsecrule)); err == nil {
found = true
break
}
}
if !found {
return fmt.Errorf("custom appsec-rule %q not in %v; fix name or location before install", appsecrule, t.CustomItemsLocation)
} Prevention
- Keep custom rule file names identical to the names referenced in test configs (including extension)
- Store custom items inside the directories listed in CustomItemsLocation
- Validate test .tests config rule names against the file listing before running tests
When it happens
Trigger: installAppsecRule called with a name that is not a hub item (HubIndex.GetItem returns nil) and no file <name> exists under any of t.CustomItemsLocation paths.
Common situations: Typo in the rule name in the test .tests config; the custom rule file lives outside the configured CustomItemsLocation (e.g. not in .tests/ or the custom dir); rule file name differs from the name referenced in the test config.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- item %s:%s not found
- no appsec_config provided
- ip not found
- no hub configuration provided
- too many levels of symbolic links
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/60c0892f6dcdbeb9.
Report an issue: GitHub.