{"record":{"id":"0f922411b1690900","repo":"infiniflow/ragflow","slug":"listoperations-tail-requires-n-to-be-within-the-v","errorCode":null,"errorMessage":"ListOperations: tail requires n to be within the valid range in strict mode, got %d","messagePattern":"ListOperations: tail requires n to be within the valid range in strict mode, got (.+?)","errorType":"validation","errorClass":"listOpPanic","httpStatus":null,"severity":"error","filePath":"internal/agent/component/list_operations.go","lineNumber":432,"sourceCode":"\t\t\tpanic(strictRangePanic(\"head\", n))\n\t\t}\n\t\treturn append([]any{}, items[:n]...)\n\t}\n\tif n < 1 {\n\t\treturn []any{}\n\t}\n\tif n > len(items) {\n\t\tn = len(items)\n\t}\n\treturn append([]any{}, items[:n]...)\n}\n\n// opTail: last n items. n < 1 → empty. Strict: 1 ≤ n ≤ len(items).\nfunc (l *ListOperationsComponent) opTail(items []any) []any {\n\tn := l.param.N\n\tif l.param.Strict {\n\t\tif n < 1 || n > len(items) {\n\t\t\tpanic(strictRangePanic(\"tail\", n))\n\t\t}\n\t\treturn append([]any{}, items[len(items)-n:]...)\n\t}\n\tif n < 1 {\n\t\treturn []any{}\n\t}\n\tif n > len(items) {\n\t\tn = len(items)\n\t}\n\treturn append([]any{}, items[len(items)-n:]...)\n}\n\n// opFilter: keep items whose _norm(v) matches the filter rule.\nfunc (l *ListOperationsComponent) opFilter(items []any) []any {\n\top, _ := l.param.Filter[\"operator\"].(string)\n\tval, _ := l.param.Filter[\"value\"].(string)\n\tout := make([]any, 0, len(items))\n\tfor _, item := range items {","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/internal/agent/component/list_operations.go#L414-L450","documentation":"opTail panics in strict mode when n < 1 or n > len(items). The tail operation returns the last n items and strict mode enforces 1 <= n <= len(items); anything outside that range panics via strictRangePanic instead of returning empty or clamping.","triggerScenarios":"ListOperations with operation tail, Strict: true, and N set to 0, a negative number, or a value larger than the input list length.","commonSituations":"Unset N defaulting to 0; dynamic counts that hit 0 on short upstream lists; fixed tail sizes assumed to fit any list but applied to filtered or split data.","solutions":["Set N within 1..len(items) — e.g. n: 1 to take only the last item","Guard dynamic N values and empty upstream lists before tail executes","Disable strict mode if clamped/empty results are acceptable for edge cases"],"exampleFix":"# before\noperation: tail\nstrict: true\nn: 10       # list has 4 items -> panic\n\n# after\noperation: tail\nstrict: true\nn: 4        # whole list; n:1 for last item only","handlingStrategy":"validation","validationCode":"if op == \"tail\" && strict && (n < 1 || n > len(items)) {\n    return fmt.Errorf(\"tail requires 1 <= n <= %d, got %d\", len(items), n)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply the same 1..len(items) bound check to tail as to head","Handle empty-list inputs upstream; strict tail can never succeed on them","Keep n parameterized from a checked source instead of hardcoded"],"tags":["go","list-operations","agent-component","strict-mode","panic","range-check"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}