usememos/memos · error

exists_one loop step must have three arguments

Error message

exists_one loop step must have three arguments

What it means

For exists_one(), the parser expects the loop step to be the ternary call _?_:_ with exactly three arguments (predicate, accu+1, accu). If the args slice has any other length, this error is thrown before the predicate is read from Args[0].

Source

Thrown at internal/filter/parser.go:889

	return "", errors.New("unsupported comprehension type (supported: exists, all, exists_one)")
}

// extractPredicate extracts the predicate expression from the comprehension loop step.
func extractPredicate(comp *exprv1.Expr_Comprehension, _ Schema) (PredicateExpr, error) {
	// The loop step is: @result || predicate(t) for exists
	//                or: @result && predicate(t) for all
	step := comp.LoopStep.GetCallExpr()
	if step == nil {
		return nil, errors.New("comprehension loop step must be a call expression")
	}

	// exists/all: accu || predicate  /  accu && predicate  -> predicate is arg[1].
	// exists_one: predicate ? accu + 1 : accu               -> predicate is arg[0].
	var predicateExpr *exprv1.Expr
	if step.Function == "_?_:_" {
		if len(step.Args) != 3 {
			return nil, errors.New("exists_one loop step must have three arguments")
		}
		predicateExpr = step.Args[0]
	} else {
		if len(step.Args) != 2 {
			return nil, errors.New("comprehension loop step must have two arguments")
		}
		predicateExpr = step.Args[1]
	}
	predicateCall := predicateExpr.GetCallExpr()
	if predicateCall == nil {
		return nil, errors.New("comprehension predicate must be a function call")
	}

	// Handle different predicate functions
	switch predicateCall.Function {
	case "_==_":
		return buildEqualsPredicate(predicateCall, comp.IterVar)
	case "startsWith":

View on GitHub (pinned to 14d757ce1f)

Solutions

  1. Use textual exists_one() in the filter, e.g. tag.exists_one(t, t == "work")
  2. If building the AST yourself, emit the canonical expansion: LoopStep = ternary(predicate, accu+1, accu) with all three args
Defensive patterns

Strategy: try-catch

Try / catch

if err := r.Render(cond); err != nil {
    if strings.Contains(err.Error(), "exists_one loop step") {
        // malformed AST; regenerate from textual exists_one()
        return errors.New("exists_one must be written as exists_one(x, predicate)")
    }
    return err
}

Prevention

When it happens

Trigger: A hand-built or rewritten exists_one comprehension whose _?_:_ call does not carry 3 args; practically only reachable from programmatic AST construction or a non-standard CEL macro expansion, since textual exists_one() always expands to a 3-arg ternary.

Common situations: Custom macros registered in a cel-go environment that emit _?_:_ with partial args; AST transformations between parse and filter conversion.

Related errors


AI-assisted analysis of usememos/memos@14d757ce1f (2026-08-15). Data as JSON: /api/errors/16494c8c36178d96. Report an issue: GitHub.