{"record":{"id":"7814a8c5e9ffa737","repo":"crowdsecurity/crowdsec","slug":"failed-to-compile-profiles-w","errorCode":null,"errorMessage":"failed to compile profiles: %w","messagePattern":"failed to compile profiles: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/apiserver/controllers/v1/controller.go","lineNumber":47,"sourceCode":"type ControllerV1Config struct {\n\tDbClient    *database.Client\n\tProfilesCfg []*csconfig.ProfileCfg\n\n\tAlertsAddChan      chan []*models.Alert\n\tDecisionDeleteChan chan []*models.Decision\n\n\tPluginChannel   chan models.ProfileAlert\n\tConsoleConfig   csconfig.ConsoleConfig\n\tTrustedIPs      []net.IPNet\n\tAutoRegisterCfg *csconfig.LocalAPIAutoRegisterCfg\n}\n\nfunc New(cfg *ControllerV1Config) (*Controller, error) {\n\tvar err error\n\n\tprofiles, err := csprofiles.NewProfile(cfg.ProfilesCfg)\n\tif err != nil {\n\t\treturn &Controller{}, fmt.Errorf(\"failed to compile profiles: %w\", err)\n\t}\n\n\tv1 := &Controller{\n\t\tDBClient:           cfg.DbClient,\n\t\tAPIKeyHeader:       middlewares.APIKeyHeader,\n\t\tProfiles:           profiles,\n\t\tAlertsAddChan:      cfg.AlertsAddChan,\n\t\tDecisionDeleteChan: cfg.DecisionDeleteChan,\n\t\tPluginChannel:      cfg.PluginChannel,\n\t\tConsoleConfig:      cfg.ConsoleConfig,\n\t\tTrustedIPs:         cfg.TrustedIPs,\n\t\tAutoRegisterCfg:    cfg.AutoRegisterCfg,\n\t}\n\n\tv1.Middlewares, err = middlewares.NewMiddlewares(cfg.DbClient)\n\tif err != nil {\n\t\treturn v1, err\n\t}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/controllers/v1/controller.go#L29-L65","documentation":"Returned by the v1 alerts/profiles controller constructor when csprofiles.NewProfile fails to compile the profile configuration (invalid YAML structure, bad filter expressions, wrong profile keys). The constructor refuses to build a Controller without valid profiles, so the API server aborts startup with this wrapped error.","triggerScenarios":"NewV1 -> New is called during API server startup with cfg.ProfilesCfg loaded from config.yaml's 'profiles' section; csprofiles.NewProfile returns an error (unparseable profile filter, invalid duration in 'decisions_since', bad expression syntax) and the constructor wraps it.","commonSituations":"Operator hand-edits profile.yaml/config.yaml and introduces a YAML type error or an invalid expr filter like 'not a valid expr'; upgrading crowdsec with an old config using removed profile fields; wrong file passed as profiles config.","solutions":["Run 'cscli capi check' or validate the profiles section with crowdsec in dry/debug mode to find the exact profile and expression failing","Fix the YAML syntax / filter expression in the profiles section of your config (usually /etc/crowdsec/config.yaml or profiles.yaml)","Restore a known-good default profiles file from the crowdsec distribution","If the error mentions an expression, test the filter with 'cscli explain' or the exprhelpers sandbox before restarting"],"exampleFix":"// before (config.yaml profiles)\nprofiles:\n  - name: bad_filter\n    filters:\n      - Alert.Remediation == true && not_a_field\n// after\nprofiles:\n  - name: valid_filter\n    filters:\n      - Alert.Remediation == true && Alert.GetScope() == 'ip'","handlingStrategy":"validation","validationCode":"// before starting the API server, compile profiles the same way the controller does\nprofiles, err := csprofiles.NewProfile(cfg.ProfilesCfg)\nif err != nil {\n    return fmt.Errorf(\"startup aborted, fix profiles config: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := server.Start(); err != nil {\n    if strings.Contains(err.Error(), \"failed to compile profiles\") {\n        log.Fatalf(\"profiles config invalid, check profiles section: %v\", err)\n    }\n}","preventionTips":["Validate profiles YAML with crowdsec/cscli after every manual edit","Keep profile filters simple and test expr filters before deploying","Pin and diff profiles config against the shipped default when upgrading","Use config management with validation (e.g. ansible + syntax check) for profiles files"],"tags":["config","profiles","startup","go"],"backgroundTag":"invalid-config-value","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"}