{"record":{"id":"deffa560f72dd53d","repo":"crowdsecurity/crowdsec","slug":"failed-to-parse-feature-flags-w","errorCode":null,"errorMessage":"failed to parse feature flags: %w","messagePattern":"failed to parse feature flags: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fflag/features.go","lineNumber":203,"sourceCode":"\n\t\tlogger.Debugf(\"Feature flag: %s=%t (from envvar). %s\", featureName, enable, feat.Description)\n\t}\n\n\treturn nil\n}\n\nfunc (fr *FeatureRegister) SetFromYaml(r io.Reader, logger *logrus.Logger) error {\n\tvar cfg []string\n\n\tbys, err := io.ReadAll(r)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// parse config file\n\tif err := yaml.Unmarshal(bys, &cfg); err != nil {\n\t\tif !errors.Is(err, io.EOF) {\n\t\t\treturn fmt.Errorf(\"failed to parse feature flags: %w\", err)\n\t\t}\n\n\t\tlogger.Debug(\"No feature flags in config file\")\n\t}\n\n\t// set features\n\tfor _, k := range cfg {\n\t\tfeat, err := fr.GetFeature(k)\n\t\tif err != nil {\n\t\t\tlogger.Errorf(\"Ignored feature flag '%s': %s\", k, err)\n\t\t\tcontinue\n\t\t}\n\n\t\terr = feat.Set(true)\n\n\t\tswitch {\n\t\tcase errors.Is(err, ErrFeatureRetired):\n\t\t\tlogger.Errorf(\"Ignored feature flag '%s': %s. %s\", k, err, feat.DeprecationMsg)","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/fflag/features.go#L185-L221","documentation":"SetFromYaml parses a feature-flags YAML document and applies it. If yaml.Unmarshal fails with anything other than io.EOF (EOF means an empty file, which is tolerated as 'no feature flags'), the parse error is wrapped and returned. It indicates the config file contains invalid YAML.","triggerScenarios":"Calling SetFromYaml(reader, logger) (directly or via SetFromYamlFile) with a reader containing syntactically invalid YAML — bad indentation, tabs, wrong types for known fields, stray characters.","commonSituations":"Hand-edited feature flag config files; tabs instead of spaces; features section not a map; a value that doesn't unmarshal into the expected field type.","solutions":["Fix the YAML syntax error reported by the wrapped message (line/column are usually included)","Replace tabs with spaces and check indentation of nested keys","Ensure the file's features section is a map of flag-name to enabled/config value","Validate the file with a YAML linter or `cscli` startup before deploying"],"exampleFix":"// bad YAML\nfeatures:\n\t\tmy-flag: true   # tabs, wrong indent\n// good YAML\nfeatures:\n  my-flag: true","handlingStrategy":"validation","validationCode":"bys, _ := io.ReadAll(r)\nif err := yaml.Unmarshal(bys, &map[string]any{}); err != nil && !errors.Is(err, io.EOF) {\n    return fmt.Errorf(\"invalid feature flags YAML: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := fr.SetFromYaml(f, logger); err != nil {\n    if strings.HasPrefix(err.Error(), \"failed to parse feature flags\") {\n        // keep previous config, surface the YAML error to the operator\n        logger.Errorf(\"fix feature_flags.yaml: %v\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Validate YAML files before deploying (yamllint or cscli startup check)","Use spaces, never tabs, in feature flag config","Keep the features section a flat map of name->value","Treat an empty file as fine — EOF is intentionally tolerated"],"tags":["go","yaml","config","feature-flags"],"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"}