{"record":{"id":"ecfc8d0274ad4c86","repo":"crowdsecurity/crowdsec","slug":"while-generating-decision-from-profile-s-w","errorCode":null,"errorMessage":"while generating decision from profile %s: %w","messagePattern":"while generating decision from profile (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csprofiles/csprofiles.go","lineNumber":191,"sourceCode":"\t\tdebugProfile := false\n\t\tif profile.Cfg.Debug != nil && *profile.Cfg.Debug {\n\t\t\tdebugProfile = true\n\t\t}\n\n\t\toutput, err := exprhelpers.Run(expression, map[string]interface{}{\"Alert\": alert}, profile.Logger, debugProfile)\n\t\tif err != nil {\n\t\t\tprofile.Logger.Warningf(\"failed to run profile expr for %s: %v\", profile.Cfg.Name, err)\n\t\t\treturn nil, matched, fmt.Errorf(\"while running expression %s: %w\", profile.Cfg.Filters[eIdx], err)\n\t\t}\n\n\t\tswitch out := output.(type) {\n\t\tcase bool:\n\t\t\tif out {\n\t\t\t\tmatched = true\n\t\t\t\t/*the expression matched, create the associated decision*/\n\t\t\t\tsubdecisions, err := profile.GenerateDecisionFromProfile(alert)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, matched, fmt.Errorf(\"while generating decision from profile %s: %w\", profile.Cfg.Name, err)\n\t\t\t\t}\n\n\t\t\t\tdecisions = append(decisions, subdecisions...)\n\t\t\t} else {\n\t\t\t\tprofile.Logger.Debugf(\"Profile %s filter is unsuccessful\", profile.Cfg.Name)\n\n\t\t\t\tif profile.Cfg.OnFailure == \"break\" {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\n\t\tdefault:\n\t\t\treturn nil, matched, fmt.Errorf(\"unexpected type %t (%v) while running '%s'\", output, output, profile.Cfg.Filters[eIdx])\n\t\t}\n\t}\n\n\treturn decisions, matched, nil\n}","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csprofiles/csprofiles.go#L173-L209","documentation":"When a profile filter evaluates to true, EvaluateProfile calls GenerateDecisionFromProfile to build the matching decisions. Any failure there (e.g. malformed decision duration, error evaluating decision scope/value expressions) is wrapped as 'while generating decision from profile <name>' and the whole evaluation returns an error with no decisions.","triggerScenarios":"A profile filter matched (true) and the associated decision template failed to generate: invalid decision fields in the profile (bad duration string, invalid scope/value expr), or an internal error producing decisions from the alert.","commonSituations":"Profile YAML defining a decision with unsupported keys or malformed nested expressions; custom scenarios/profiles written for older CrowdSec versions whose decision schema changed; alerts lacking data the decision expr expects.","solutions":["Inspect the wrapped inner error for the concrete cause (often duration parse or expr evaluation).","Validate the profile's decisions block: required fields present, duration parseable, expressions valid.","Compare your custom profile against the stock /etc/crowdsec/profiles.yaml.","Enable debug logging and re-trigger an alert to see which decision field fails."],"exampleFix":"// before (profiles.yaml decision)\ndecisions:\n  - type: ban\n    duration: 4hrs\n// after\ndecisions:\n  - type: ban\n    duration: 4h","handlingStrategy":"try-catch","validationCode":"// validate decisions config before use\nfor _, d := range profile.Decisions {\n    if d.Duration != \"\" {\n        if _, err := cstime.ParseDurationWithDays(d.Duration); err != nil {\n            return fmt.Errorf(\"invalid decision duration %q: %w\", d.Duration, err)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"decisions, matched, err := profile.EvaluateProfile(alert)\nif err != nil {\n    log.Warnf(\"decision generation failed for profile %s: %v\", profile.Cfg.Name, err)\n    return\n}","preventionTips":["Mirror the stock profiles.yaml structure when writing custom profiles","Keep decision fields (type, duration, scope) to known-good values","Test profile end-to-end with a simulated alert before production"],"tags":["profile","decision","config"],"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-14T00:17:10.932Z"}