{"record":{"id":"a3f51a8f5b55795e","repo":"crowdsecurity/crowdsec","slug":"while-decoding-s-w","errorCode":null,"errorMessage":"while decoding %s: %w","messagePattern":"while decoding (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csconfig/profiles.go","lineNumber":61,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\n\treader := bytes.NewReader(fcontent)\n\n\tdec := yaml.NewDecoder(reader)\n\tdec.KnownFields(true)\n\n\tfor {\n\t\tt := ProfileCfg{}\n\n\t\terr = dec.Decode(&t)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, io.EOF) {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\treturn fmt.Errorf(\"while decoding %s: %w\", c.ProfilesPath, err)\n\t\t}\n\n\t\tc.Profiles = append(c.Profiles, &t)\n\t}\n\n\tif len(c.Profiles) == 0 {\n\t\treturn errors.New(\"zero profiles loaded for LAPI\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":43,"sourceCodeEnd":73,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csconfig/profiles.go#L43-L73","documentation":"LoadProfiles streams the profiles yaml file through a yaml.Decoder, decoding one profile document per iteration until EOF. A decode error on any non-final document (bad YAML syntax, wrong field types, unknown fields under strict decoding) is wrapped with the profiles path. Profiles are required for notification workflows, so startup aborts.","triggerScenarios":"profiles.yaml (default /etc/crowdsec/profiles.yaml) contains malformed YAML or a document after the first whose schema is wrong — e.g. filters/name/notifications fields with wrong types, or a second profile entry with invalid structure.","commonSituations":"Operators append custom profiles to the stock file with bad indentation or an extra document separator '---' followed by broken content; upgrades move fields around making old profiles invalid.","solutions":["Run `yamllint /etc/crowdsec/profiles.yaml` and fix the syntax error it reports (the wrapped %w error names the line).","If you appended a custom profile, check the '---' separator placement and indentation of the added document.","Compare field names/types against the upstream profiles.yaml example (filters, notifications, name).","Restore the stock profiles.yaml from the crowdsec package and reapply customizations one at a time."],"exampleFix":"// before (profiles.yaml, wrong type)\n- name: foo\n  notifications: email   # string, must be a list\n// after\n- name: foo\n  notifications:\n    - email_default","handlingStrategy":"try-catch","validationCode":"f, err := os.Open(profilesPath)\nif err != nil { return err }\ndefer f.Close()\ndec := yaml.NewDecoder(f)\nfor {\n    var t map[string]any\n    if err := dec.Decode(&t); err != nil {\n        if errors.Is(err, io.EOF) { break }\n        return fmt.Errorf(\"profiles.yaml invalid: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.LoadProfiles(); err != nil {\n    if strings.Contains(err.Error(), \"while decoding\") {\n        // point the operator at the profiles.yaml line named in the wrapped error\n    }\n    return err\n}","preventionTips":["Validate profiles.yaml with yamllint after every edit.","When appending custom profiles, keep each document separated by a proper '---' line.","Diff against the upstream profiles.yaml after upgrades to catch schema changes."],"tags":["yaml","profiles","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-14T00:17:10.932Z"}