{"record":{"id":"b8c79909cb30f7d1","repo":"crowdsecurity/crowdsec","slug":"medianinterval-expects-exactly-one-parameter-a-sl","errorCode":null,"errorMessage":"MedianInterval expects exactly one parameter: a slice of times","messagePattern":"MedianInterval expects exactly one parameter: a slice of times","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/helpers.go","lineNumber":706,"sourceCode":"\n\t// Sort times in ascending order\n\tsort.Slice(times, func(i, j int) bool {\n\t\treturn times[i].Before(times[j])\n\t})\n\n\tvar total time.Duration\n\tfor i := 1; i < len(times); i++ {\n\t\ttotal += times[i].Sub(times[i-1])\n\t}\n\n\taverage := time.Duration(int64(total) / int64(len(times)-1))\n\treturn average, nil\n}\n\n// func MedianInterval(times []time.Time) (time.Duration, error)\nfunc MedianInterval(params ...any) (any, error) {\n\tif len(params) != 1 {\n\t\treturn 0, errors.New(\"MedianInterval expects exactly one parameter: a slice of times\")\n\t}\n\n\tvar times []time.Time\n\n\t// Handle both []time.Time and []interface{} (from expr map function)\n\tswitch v := params[0].(type) {\n\tcase []time.Time:\n\t\ttimes = v\n\tcase []interface{}:\n\t\ttimes = make([]time.Time, len(v))\n\t\tfor i, item := range v {\n\t\t\tt, ok := item.(time.Time)\n\t\t\tif !ok {\n\t\t\t\treturn 0, fmt.Errorf(\"element at index %d is not a time.Time\", i)\n\t\t\t}\n\t\t\ttimes[i] = t\n\t\t}\n\tdefault:","sourceCodeStart":688,"sourceCodeEnd":724,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/helpers.go#L688-L724","documentation":"Arity guard in the MedianInterval expr helper: it was invoked from a scenario expression with more or fewer than exactly one argument. The single argument must be the slice of times to measure intervals over.","triggerScenarios":"Thrown at pkg/exprhelpers/helpers.go:706 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call MedianInterval with exactly one parameter, e.g. MedianInterval(EvtInt1.GetAll())","Remove extra arguments from the scenario expression"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}