{"record":{"id":"4751f16de77b0235","repo":"crowdsecurity/crowdsec","slug":"medianinterval-expects-a-slice-of-times","errorCode":null,"errorMessage":"MedianInterval expects a slice of times","messagePattern":"MedianInterval expects a slice of times","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/helpers.go","lineNumber":725,"sourceCode":"\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:\n\t\treturn 0, errors.New(\"MedianInterval expects a slice of times\")\n\t}\n\n\tif len(times) < 2 {\n\t\treturn 0, errors.New(\"need at least two times to calculate a median\")\n\t}\n\n\t// Sort times\n\tsort.Slice(times, func(i, j int) bool {\n\t\treturn times[i].Before(times[j])\n\t})\n\n\t// Compute intervals\n\tintervals := make([]time.Duration, len(times)-1)\n\tfor i := 1; i < len(times); i++ {\n\t\tintervals[i-1] = times[i].Sub(times[i-1])\n\t}\n\n\t// Sort intervals for median calculation","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/helpers.go#L707-L743","documentation":"Type guard in MedianInterval: the single argument is neither []time.Time nor []interface{} of time.Time values, so there is nothing to compute intervals from (e.g. a string or number was passed from the expr expression).","triggerScenarios":"Thrown at pkg/exprhelpers/helpers.go:725 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a slice of time.Time values, typically from EvtInt marshaling in the scenario","Ensure the source event field actually contains parsed timestamps, not strings"],"exampleFix":null,"handlingStrategy":"type-guard","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-14T00:17:10.932Z"}