infiniflow/ragflow · error · listOpPanic
ListOperations: nth requires n to be within the valid range
Error message
ListOperations: nth requires n to be within the valid range in strict mode, got %d
What it means
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).
Source
Thrown at internal/agent/component/list_operations.go:386
}
}
// Outputs returns the transformed list plus head/tail scalars.
func (l *ListOperationsComponent) Outputs() map[string]string {
return map[string]string{
"result": "Transformed list (per the configured operation).",
"first": "First element of the result (nil for empty result).",
"last": "Last element of the result (nil for empty result).",
}
}
// opNth: 1-indexed for positive n, -N (from end) for negative n.
// n=0 → empty (or error in strict mode).
func (l *ListOperationsComponent) opNth(items []any) []any {
n := l.param.N
if n == 0 {
if l.param.Strict {
panic(strictRangePanic("nth", n))
}
return []any{}
}
if n > 0 {
if n <= len(items) {
return []any{items[n-1]}
}
if l.param.Strict {
panic(strictRangePanic("nth", n))
}
return []any{}
}
absN := -n
if absN <= len(items) {
return []any{items[n]}
}
if l.param.Strict {
panic(strictRangePanic("nth", n))View on GitHub (pinned to 554fb1133a)
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
Example fix
# before operation: nth strict: true n: 0 # panic: nth requires n to be within the valid range # after operation: nth strict: true n: 1 # first element
Defensive patterns
Strategy: validation
Validate before calling
if op == "nth" && strict && n == 0 {
return fmt.Errorf("nth with strict=true requires non-zero n")
} Prevention
- 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
When it happens
Trigger: Running a ListOperations component with operation nth, Strict: true, and N set to 0 on any input list.
Common situations: 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.
Related errors
- ListOperations: head requires n to be within the valid range
- ListOperations: tail requires n to be within the valid range
- {operation} requires n to be within the valid range in stric
- failed to initialize logger: {err}
- Invoke: invalid proxy URL %q: %v
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/0af07414f38949a0.
Report an issue: GitHub.