{"record":{"id":"0af07414f38949a0","repo":"infiniflow/ragflow","slug":"listoperations-nth-requires-n-to-be-within-the-va","errorCode":null,"errorMessage":"ListOperations: nth requires n to be within the valid range in strict mode, got %d","messagePattern":"ListOperations: nth 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":386,"sourceCode":"\t}\n}\n\n// Outputs returns the transformed list plus head/tail scalars.\nfunc (l *ListOperationsComponent) Outputs() map[string]string {\n\treturn map[string]string{\n\t\t\"result\": \"Transformed list (per the configured operation).\",\n\t\t\"first\":  \"First element of the result (nil for empty result).\",\n\t\t\"last\":   \"Last element of the result (nil for empty result).\",\n\t}\n}\n\n// opNth: 1-indexed for positive n, -N (from end) for negative n.\n// n=0 → empty (or error in strict mode).\nfunc (l *ListOperationsComponent) opNth(items []any) []any {\n\tn := l.param.N\n\tif n == 0 {\n\t\tif l.param.Strict {\n\t\t\tpanic(strictRangePanic(\"nth\", n))\n\t\t}\n\t\treturn []any{}\n\t}\n\tif n > 0 {\n\t\tif n <= len(items) {\n\t\t\treturn []any{items[n-1]}\n\t\t}\n\t\tif l.param.Strict {\n\t\t\tpanic(strictRangePanic(\"nth\", n))\n\t\t}\n\t\treturn []any{}\n\t}\n\tabsN := -n\n\tif absN <= len(items) {\n\t\treturn []any{items[n]}\n\t}\n\tif l.param.Strict {\n\t\tpanic(strictRangePanic(\"nth\", n))","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/internal/agent/component/list_operations.go#L368-L404","documentation":"opNth panics in strict mode when n == 0. Indexing semantics are 1-indexed for positive n and -N counts from the end, so 0 selects nothing; strict mode (l.param.Strict) treats that as a caller bug and panics via strictRangePanic instead of returning an empty list (the non-strict behavior).","triggerScenarios":"Running a ListOperations component with operation nth, Strict: true, and N set to 0 on any input list.","commonSituations":"N is wired to an upstream output that evaluates to 0 (e.g. a computed index or a default value), or a template field left at its zero default while strict mode was enabled to catch bad indices.","solutions":["Set N to a non-zero value: >= 1 for 1-indexed from the start, or negative (e.g. -1 for last element)","If N comes from an upstream node, add a guard/branch so it is never 0 when strict mode is on","If an empty result for n=0 is acceptable, disable strict mode (Strict: false) to get the lenient []any{} return"],"exampleFix":"# before\noperation: nth\nstrict: true\nn: 0        # panic: nth requires n to be within the valid range\n\n# after\noperation: nth\nstrict: true\nn: 1        # first element","handlingStrategy":"validation","validationCode":"if op == \"nth\" && strict && n == 0 {\n    return fmt.Errorf(\"nth with strict=true requires non-zero n\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat n=0 for nth as a config error and reject it at workflow-save time","When wiring N from upstream nodes, add an IF/branch for the zero case","Keep strict mode off in exploratory canvases; enable it only for validated production flows"],"tags":["go","list-operations","agent-component","strict-mode","panic","indexing"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}