{"record":{"id":"279b3db33c8027fe","repo":"crowdsecurity/crowdsec","slug":"s-w-279b3d","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csconfig/config.go","lineNumber":70,"sourceCode":"\tif err != nil {\n\t\treturn nil, \"\", err\n\t}\n\n\tconfigData := csstring.StrictExpand(string(fcontent), os.LookupEnv)\n\tcfg := Config{\n\t\tFilePath:     configFile,\n\t\tDisableAgent: disableAgent,\n\t\tDisableAPI:   disableAPI,\n\t}\n\n\tdec := yaml.NewDecoder(strings.NewReader(configData))\n\tdec.KnownFields(true)\n\n\terr = dec.Decode(&cfg)\n\tif err != nil {\n\t\tif !errors.Is(err, io.EOF) {\n\t\t\t// this is actually the \"merged\" yaml\n\t\t\treturn nil, \"\", fmt.Errorf(\"%s: %w\", configFile, err)\n\t\t}\n\t}\n\n\tif cfg.Prometheus == nil {\n\t\tcfg.Prometheus = &PrometheusCfg{}\n\t}\n\n\tif cfg.Prometheus.ListenAddr == \"\" {\n\t\tcfg.Prometheus.ListenAddr = \"127.0.0.1\"\n\t\tlog.Debugf(\"prometheus.listen_addr is empty, defaulting to %s\", cfg.Prometheus.ListenAddr)\n\t}\n\n\tif cfg.Prometheus.ListenPort == 0 {\n\t\tcfg.Prometheus.ListenPort = 6060\n\t\tlog.Debugf(\"prometheus.listen_port is empty or zero, defaulting to %d\", cfg.Prometheus.ListenPort)\n\t}\n\n\tif err = cfg.loadCommon(); err != nil {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csconfig/config.go#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the inner error: yaml decode errors name the exact line and unknown/invalid field","Remove or rename the offending key to the correct one for your crowdsec version","Compare against a pristine config from the package (config/config.yaml) or `cscli config show`","Fix YAML indentation/syntax at the reported line"],"exampleFix":"// before (config.yaml)\napi:\n  server:\n    listning_port: 8080\n// after\napi:\n  server:\n    listening_port: 8080","handlingStrategy":"try-catch","validationCode":"// strict-decode a candidate config before deploying\nvar probe Config\ndec := yaml.NewDecoder(strings.NewReader(rawYAML))\ndec.KnownFields(true)\nif err := dec.Decode(&probe); err != nil { return fmt.Errorf(\"config invalid: %w\", err) }","typeGuard":null,"tryCatchPattern":"cfg, cfgFile, err := csconfig.NewConfig(paths, disableCli)\nif err != nil {\n\t// message begins with the offending config file path\n\tlog.Fatalf(\"invalid configuration (%v) — check the named file\", err)\n}","preventionTips":["Run `cscli config check` after every config edit","Diff your config against the version shipped by your crowdsec release before upgrading","Keep keys lowercase/snake_case exactly as documented; no invented keys"],"tags":["config","yaml","validation","strict-decoding"],"backgroundTag":"schema-validation-failed","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"}