{"record":{"id":"071c9e2ee313d4ec","repo":"crowdsecurity/crowdsec","slug":"unable-to-parse-yaml-file-s-w","errorCode":null,"errorMessage":"unable to parse yaml file %s : %w","messagePattern":"unable to parse yaml file (.+?) : %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/appsec/appsec.go","lineNumber":673,"sourceCode":"\t/* wc.Name is actually the datasource name.*/\n\twc.Logger = wc.Logger.Dup().WithField(\"name\", wc.Name)\n\twc.Logger.Logger.SetLevel(*wc.LogLevel)\n}\n\nfunc (wc *AppsecConfig) LoadByPath(file string) error {\n\twc.Logger.Debugf(\"loading config %s\", file)\n\n\tyamlFile, err := os.ReadFile(file)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to read file %s : %w\", file, err)\n\t}\n\n\t// as  LoadByPath can be called several time, we append rules/hooks, but override other options\n\tvar tmp AppsecConfig\n\n\terr = yaml.UnmarshalStrict(yamlFile, &tmp)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to parse yaml file %s : %w\", file, err)\n\t}\n\n\t// Normalize phase-scoped sections: merge rules, options, and variables_tracking\n\t// into flat fields. Hooks stay in the phase sections for Build() to compile separately.\n\ttmp.normalizePhaseScoped()\n\n\tif wc.Name == \"\" && tmp.Name != \"\" {\n\t\twc.Name = tmp.Name\n\t}\n\n\t// We can append rules/hooks\n\tif tmp.OutOfBandRules != nil {\n\t\twc.OutOfBandRules = append(wc.OutOfBandRules, tmp.OutOfBandRules...)\n\t}\n\n\tif tmp.InBandRules != nil {\n\t\twc.InBandRules = append(wc.InBandRules, tmp.InBandRules...)\n\t}","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/appsec/appsec.go#L655-L691","documentation":"After reading the appsec config file, LoadByPath unmarshals it into a temporary AppsecConfig with yaml.UnmarshalStrict. Strict mode rejects unknown keys, so this error fires both for syntactically invalid YAML and for config keys that do not exist on the struct. The wrapped yaml error names the exact line and offending key.","triggerScenarios":"LoadByPath on a YAML file with syntax errors (bad indentation, tabs, unclosed quotes); a typo'd or unknown top-level key (strict unmarshaling); a value of the wrong type for a known field.","commonSituations":"Hand-edited appsec-config with a misspelled option like 'on_sucess' instead of 'on_success'; tabs instead of spaces; mixing appsec-config keys into a rules file loaded as appsec config; config from an older/newer CrowdSec version using removed keys.","solutions":["Read the wrapped yaml error line/column and fix the YAML syntax or the unknown key at that line","Compare your keys against the documented AppsecConfig fields for your CrowdSec version","Replace tabs with spaces and validate indentation with a YAML linter","Pin configs to keys supported by your installed version when copying examples from newer docs"],"exampleFix":"// before\non_sucess: break\n// after\non_success: break","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strict-lint YAML in CI","No tabs; copy documented keys only"],"tags":["appsec","yaml","config"],"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-14T05:17:10.506Z"}