crowdsecurity/crowdsec · error
parsing: %w
Error message
parsing: %w
What it means
NewTest reads the test directory's config file and unmarshals it with yaml.Unmarshal; a syntax/type error in the YAML is wrapped as 'parsing: %w'. (A missing config file is only logged earlier, so this specific error means the file existed but could not be parsed.)
Source
Thrown at pkg/hubtest/hubtest_item.go:122
func NewTest(name string, hubTest *HubTest, dataDir string) (*HubTestItem, error) {
testPath := filepath.Join(hubTest.HubTestPath, name)
runtimeFolder := filepath.Join(testPath, "runtime")
runtimeHubFolder := filepath.Join(runtimeFolder, "hub")
configFilePath := filepath.Join(testPath, "config.yaml")
resultPath := filepath.Join(testPath, "results")
// read test configuration file
configFileData := &HubTestItemConfig{}
yamlFile, err := os.ReadFile(configFilePath)
if err != nil {
log.Printf("no config file found in '%s': %v", testPath, err)
}
err = yaml.Unmarshal(yamlFile, configFileData)
if err != nil {
return nil, fmt.Errorf("parsing: %w", err)
}
parserAssertFilePath := filepath.Join(testPath, ParserAssertFileName)
parserAssert := NewParserAssert(parserAssertFilePath)
scenarioAssertFilePath := filepath.Join(testPath, ScenarioAssertFileName)
scenarioAssert := NewScenarioAssert(scenarioAssertFilePath)
// force own_data_dir for backard compatibility
if name == "magento-ccs-by-as" || name == "magento-ccs-by-country" || name == "geoip-enrich" {
configFileData.OwnDataDir = true
}
if configFileData.OwnDataDir {
dataDir = filepath.Join(runtimeFolder, "data")
}
return &HubTestItem{View on GitHub (pinned to 909b515798)
Solutions
- Read the wrapped YAML library error in the message; it usually names the exact line/column.
- Fix indentation (spaces, never tabs) and quoting in the test's config.yaml.
- Validate the file with a YAML linter/parser before re-running the test.
- Restore the original file from git if local edits caused it: `git checkout -- tests/<name>/config.yaml`.
Example fix
// before (config.yaml) parsers: - foo // after (use spaces) parsers: - foo
Defensive patterns
Strategy: validation
Validate before calling
import "gopkg.in/yaml.v3"
func validYAML(b []byte) error {
var v map[string]interface{}
return yaml.Unmarshal(b, &v)
} Try / catch
_, err := h.LoadTestItem(name)
var ye *yaml.TypeError
if errors.As(err, &inner) && strings.Contains(err.Error(), "parsing:") {
log.Printf("fix YAML in %s/config.yaml: %v", name, inner)
} Prevention
- Use spaces, never tabs, in test config.yaml files.
- Quote values containing ':' or special characters.
- Run a YAML linter on edited test configs before committing.
When it happens
Trigger: LoadTestItem -> NewTest with a config.yaml (or equivalent) whose content is invalid YAML: bad indentation, tabs, duplicate keys the decoder rejects, or fields of the wrong type.
Common situations: Hand-editing test config and mixing tabs/spaces; forgetting to quote values containing colons; merging upstream test changes with local edits; pasting YAML from docs with smart quotes.
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/4013f82deede73d8.
Report an issue: GitHub.