{"record":{"id":"07fac373f725300d","repo":"crowdsecurity/crowdsec","slug":"parsing-w","errorCode":null,"errorMessage":"parsing: %w","messagePattern":"parsing: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/coverage.go","lineNumber":60,"sourceCode":"\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)\n\t}\n\n\tfor _, appsecTestConfigPath := range appsecTestConfigs {\n\t\tconfigFileData := &HubTestItemConfig{}\n\n\t\tyamlFile, err := os.ReadFile(appsecTestConfigPath)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"unable to open appsec test config file '%s': %s\", appsecTestConfigPath, err)\n\t\t\tcontinue\n\t\t}\n\n\t\terr = yaml.Unmarshal(yamlFile, configFileData)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"parsing: %w\", err)\n\t\t}\n\n\t\tfor _, appsecRulesFile := range configFileData.AppsecRules {\n\t\t\tappsecRuleData := &appsec_rule.CustomRule{}\n\n\t\t\tyamlFile, err := os.ReadFile(appsecRulesFile)\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"unable to open appsec rule '%s': %s\", appsecRulesFile, err)\n\t\t\t}\n\n\t\t\terr = yaml.Unmarshal(yamlFile, appsecRuleData)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing: %w\", err)\n\t\t\t}\n\n\t\t\tappsecRuleName := appsecRuleData.Name\n\n\t\t\tfor idx, cov := range coverage {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/coverage.go#L42-L78","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"# before (broken)\nappsec-rules: rules.yaml\n# after\nappsec-rules:\n  - rules.yaml","handlingStrategy":"try-catch","validationCode":"var probe map[string]any\nif err := yaml.Unmarshal(data, &probe); err != nil {\n\treturn fmt.Errorf(\"invalid YAML in %s: %w\", path, err)\n}\nif _, ok := probe[\"appsec-rules\"]; ok {\n\tif _, ok := probe[\"appsec-rules\"].([]any); !ok {\n\t\treturn fmt.Errorf(\"%s: 'appsec-rules' must be a list\", path)\n\t}\n}","typeGuard":null,"tryCatchPattern":"_, err := h.GetAppsecCoverage(hubDir)\nvar yamlErr *yaml.TypeError\nif err != nil && strings.HasPrefix(err.Error(), \"parsing:\") {\n\tif errors.As(err, &yamlErr) {\n\t\t// fix the offending field reported by yamlErr\n\t}\n\t// else: syntax error — lint the YAML file\n}","preventionTips":["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"],"tags":["yaml","parsing","hub-test"],"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"}