crowdsecurity/crowdsec · error

%s: %w

Error message

%s: %w

What it means

NewConfig decodes the merged YAML configuration with yaml.KnownFields(true), meaning unknown keys are rejected. A decode error that is not EOF (e.g. unknown config key, wrong value type, malformed YAML) is wrapped with the config file path as prefix. This is the top-level 'your config file is wrong' error.

Source

Thrown at pkg/csconfig/config.go:70

	if err != nil {
		return nil, "", err
	}

	configData := csstring.StrictExpand(string(fcontent), os.LookupEnv)
	cfg := Config{
		FilePath:     configFile,
		DisableAgent: disableAgent,
		DisableAPI:   disableAPI,
	}

	dec := yaml.NewDecoder(strings.NewReader(configData))
	dec.KnownFields(true)

	err = dec.Decode(&cfg)
	if err != nil {
		if !errors.Is(err, io.EOF) {
			// this is actually the "merged" yaml
			return nil, "", fmt.Errorf("%s: %w", configFile, err)
		}
	}

	if cfg.Prometheus == nil {
		cfg.Prometheus = &PrometheusCfg{}
	}

	if cfg.Prometheus.ListenAddr == "" {
		cfg.Prometheus.ListenAddr = "127.0.0.1"
		log.Debugf("prometheus.listen_addr is empty, defaulting to %s", cfg.Prometheus.ListenAddr)
	}

	if cfg.Prometheus.ListenPort == 0 {
		cfg.Prometheus.ListenPort = 6060
		log.Debugf("prometheus.listen_port is empty or zero, defaulting to %d", cfg.Prometheus.ListenPort)
	}

	if err = cfg.loadCommon(); err != nil {

View on GitHub (pinned to 909b515798)

Solutions

  1. Read the inner error: yaml decode errors name the exact line and unknown/invalid field
  2. Remove or rename the offending key to the correct one for your crowdsec version
  3. Compare against a pristine config from the package (config/config.yaml) or `cscli config show`
  4. Fix YAML indentation/syntax at the reported line

Example fix

// before (config.yaml)
api:
  server:
    listning_port: 8080
// after
api:
  server:
    listening_port: 8080
Defensive patterns

Strategy: try-catch

Validate before calling

// strict-decode a candidate config before deploying
var probe Config
dec := yaml.NewDecoder(strings.NewReader(rawYAML))
dec.KnownFields(true)
if err := dec.Decode(&probe); err != nil { return fmt.Errorf("config invalid: %w", err) }

Try / catch

cfg, cfgFile, err := csconfig.NewConfig(paths, disableCli)
if err != nil {
	// message begins with the offending config file path
	log.Fatalf("invalid configuration (%v) — check the named file", err)
}

Prevention

When it happens

Trigger: Loading any config.yaml (crowdsec, cscli, or a test harness) that contains a key not in the Config struct, a wrong type (string where int expected), or invalid YAML syntax.

Common situations: Typo'd config keys (e.g. `api_servr:`); leftover keys from an older crowdsec version removed in the current one; pasting snippet with wrong indentation; wrong type like `port: "8080"` quoted when an int is required.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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