crowdsecurity/crowdsec · error
parsing: %w
Error message
parsing: %w
What it means
GetAppsecCoverage unmarshals each .appsec-tests config.yaml into HubTestItemConfig with yaml.Unmarshal and wraps failures as 'parsing: ...'. It means a test config YAML is syntactically invalid or its structure doesn't match the expected fields (the same wrapper is reused for the referenced appsec rule files).
Source
Thrown at pkg/hubtest/coverage.go:60
// parser the expressions a-la-oneagain
appsecTestConfigs, err := filepath.Glob(filepath.Join(hubDir, ".appsec-tests", "*", "config.yaml"))
if err != nil {
return nil, fmt.Errorf("while find appsec-tests config: %w", err)
}
for _, appsecTestConfigPath := range appsecTestConfigs {
configFileData := &HubTestItemConfig{}
yamlFile, err := os.ReadFile(appsecTestConfigPath)
if err != nil {
log.Printf("unable to open appsec test config file '%s': %s", appsecTestConfigPath, err)
continue
}
err = yaml.Unmarshal(yamlFile, configFileData)
if err != nil {
return nil, fmt.Errorf("parsing: %w", err)
}
for _, appsecRulesFile := range configFileData.AppsecRules {
appsecRuleData := &appsec_rule.CustomRule{}
yamlFile, err := os.ReadFile(appsecRulesFile)
if err != nil {
log.Printf("unable to open appsec rule '%s': %s", appsecRulesFile, err)
}
err = yaml.Unmarshal(yamlFile, appsecRuleData)
if err != nil {
return nil, fmt.Errorf("parsing: %w", err)
}
appsecRuleName := appsecRuleData.Name
for idx, cov := range coverage {View on GitHub (pinned to 909b515798)
Solutions
- Run the offending YAML through a linter/parser (yamllint) to find the syntax error at the file path from the wrapped error message
- Fix type mismatches: appsec-rules must be a list of file paths, scalar fields must have the right types
- Restore the config.yaml or rule file from the upstream hub branch if it was locally modified
Example fix
# before (broken) appsec-rules: rules.yaml # after appsec-rules: - rules.yaml
Defensive patterns
Strategy: try-catch
Validate before calling
var probe map[string]any
if err := yaml.Unmarshal(data, &probe); err != nil {
return fmt.Errorf("invalid YAML in %s: %w", path, err)
}
if _, ok := probe["appsec-rules"]; ok {
if _, ok := probe["appsec-rules"].([]any); !ok {
return fmt.Errorf("%s: 'appsec-rules' must be a list", path)
}
} Try / catch
_, err := h.GetAppsecCoverage(hubDir)
var yamlErr *yaml.TypeError
if err != nil && strings.HasPrefix(err.Error(), "parsing:") {
if errors.As(err, &yamlErr) {
// fix the offending field reported by yamlErr
}
// else: syntax error — lint the YAML file
} Prevention
- Lint all .appsec-tests config.yaml files with yamllint before committing
- Keep appsec-rules entries as a proper YAML list of file paths
- Restore locally modified test configs from the upstream hub branch when parsing fails after an update
When it happens
Trigger: yaml.Unmarshal fails on a config.yaml under hubDir/.appsec-tests/*/ (or on a file listed in its appsec-rules: entries) due to bad YAML syntax or type mismatches (e.g. appsec-rules is a string instead of a list).
Common situations: Hand-edited test config with indentation/tab errors; appsec-rules entries pointing to rule files with malformed YAML; duplicate keys or wrong types after a hub branch update.
Related errors
- while parsing capi whitelist file '%s': %w
- parsing console config file '%s': %w
- document %d: %w
- failed to parse %s: %w
- parsing: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/07fac373f725300d.
Report an issue: GitHub.