{"record":{"id":"a8b952134fb9ac38","repo":"crowdsecurity/crowdsec","slug":"unexpected-type-t-v-while-running-s","errorCode":null,"errorMessage":"unexpected type %t (%v) while running '%s'","messagePattern":"unexpected type %t \\((.+?)\\) while running '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csprofiles/csprofiles.go","lineNumber":204,"sourceCode":"\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}\n","sourceCodeStart":186,"sourceCodeEnd":210,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csprofiles/csprofiles.go#L186-L210","documentation":"exprhelpers.Run is expected to return a bool for profile filters. If the filter expression evaluates to a non-boolean type (string, int, nil, etc.), EvaluateProfile hits the default switch case and returns this error naming the offending type and expression. It indicates the profile filter does not produce a boolean result.","triggerScenarios":"A profile filter expression whose last evaluated value is not bool: e.g. `filter: Alert.Remediation` returning nil, `filter: Alert.GetEventString('x')` returning a string, or a numeric/arithmetic expression without a comparison.","commonSituations":"Hand-written filters omitting a comparison operator; copying a parser/whitelist expression that returns a string into a profile filter; YAML quoting making what looks like a bool a string.","solutions":["Make the filter's final expression a boolean comparison (==, !=, in, matches, etc.).","If it returns a string, wrap it: `Alert.GetEventString('x') == 'expected'`.","Test the expression returns true/false in an expr sandbox against an Alert.","Check for missing comparison caused by YAML quote stripping."],"exampleFix":"// before\nfilter: Alert.Remediation\n// after\nfilter: \"Alert.Remediation == true\"","handlingStrategy":"validation","validationCode":"// ensure the filter is a boolean expression\nout, err := expr.Eval(filter, env)\nif err != nil {\n    return err\n}\nif _, ok := out.(bool); !ok {\n    return fmt.Errorf(\"filter %q must evaluate to bool, got %T\", filter, out)\n}","typeGuard":"func isBool(v interface{}) bool { _, ok := v.(bool); return ok }","tryCatchPattern":"decisions, matched, err := profile.EvaluateProfile(alert)\nif err != nil && strings.Contains(err.Error(), \"unexpected type\") {\n    log.Warnf(\"non-bool filter, skipping profile: %v\", err)\n    return\n}","preventionTips":["End every filter with an explicit comparison operator","Beware YAML quote stripping turning booleans into strings","Sandbox-test that filters return true/false before deploying"],"tags":["expr","type-mismatch","profile"],"backgroundTag":"type-mismatch","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"}