crowdsecurity/crowdsec · error

while parsing simulation file '%s': %w

Error message

while parsing simulation file '%s': %w

What it means

LoadSimulation parses simulation.yaml with a strict decoder (KnownFields(true)) into simCfg. Any decode error other than EOF (empty file) is wrapped with the simulation file path. Strict mode means unknown keys also fail, catching outdated or misspelled config fields early at startup.

Source

Thrown at pkg/csconfig/simulation.go:54

	simCfg := SimulationConfig{}

	if c.ConfigPaths.SimulationFilePath == "" {
		c.ConfigPaths.SimulationFilePath = filepath.Join(c.ConfigPaths.ConfigDir, "simulation.yaml")
	}

	patcher := csyaml.NewPatcher(c.ConfigPaths.SimulationFilePath, ".local")

	rcfg, err := patcher.MergedPatchContent()
	if err != nil {
		return err
	}

	dec := yaml.NewDecoder(bytes.NewReader(rcfg))
	dec.KnownFields(true)

	if err := dec.Decode(&simCfg); err != nil {
		if !errors.Is(err, io.EOF) {
			return fmt.Errorf("while parsing simulation file '%s': %w", c.ConfigPaths.SimulationFilePath, err)
		}
	}

	if c.Crowdsec != nil {
		c.Crowdsec.SimulationConfig = simCfg
	}

	if c.Cscli != nil {
		c.Cscli.SimulationConfig = simCfg
	}

	return nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Run `yamllint /etc/crowdsec/simulation.yaml` and fix the reported syntax/line.
  2. Remove unknown fields — strict decoding rejects them; valid content is a top-level 'exclusions' list.
  3. If you still use the legacy boolean form ('simulation: true'), remove it — it is no longer part of the schema.
  4. To start clean, replace the file with an empty 'exclusions: []' document, or delete it if simulation is unused.

Example fix

// before (legacy simulation.yaml)
simulation: true
// after
exclusions:
  - crowdsecurity/http-bf-wordpress
Defensive patterns

Strategy: validation

Validate before calling

data, err := os.ReadFile(simPath)
if err != nil { return err }
var v struct {
    Exclusions []string `yaml:"exclusions"`
}
dec := yaml.NewDecoder(bytes.NewReader(data))
dec.KnownFields(true)
if err := dec.Decode(&v); err != nil && !errors.Is(err, io.EOF) {
    return fmt.Errorf("simulation.yaml invalid: %w", err)
}

Try / catch

if err := cfg.LoadSimulation(); err != nil {
    if strings.Contains(err.Error(), "while parsing simulation file") {
        // restore default simulation.yaml or drop unknown fields
    }
    return err
}

Prevention

When it happens

Trigger: simulation.yaml contains invalid YAML syntax, or unknown/renamed fields (KnownFields is enabled), e.g. an old 'simulation: true' boolean form left over from legacy configs where the current schema expects an exclusion list.

Common situations: Upgrading crowdsec with a stale simulation.yaml written for an older schema; hand edits adding typos like 'exlusions:'; a partially truncated file from a failed config sync.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/f4607f878b0856f8. Report an issue: GitHub.