usememos/memos · error

comparison expects two arguments

Error message

comparison expects two arguments

What it means

Returned by buildComparisonCondition (internal/filter/parser.go) when a comparison call (_==_, _!=_, _<_, _>_, _<=_, _>=_) does not carry exactly 2 arguments. Standard CEL comparisons are binary, so this indicates an unusual AST rather than ordinary user syntax.

Source

Thrown at internal/filter/parser.go:121

	case "matches":
		return buildMatchesCondition(call, pc.schema)
	case "sets.contains", "sets.intersects", "sets.equivalent":
		return buildSetCondition(call, pc)
	default:
		val, ok, err := evaluateBool(call)
		if err != nil {
			return nil, err
		}
		if ok {
			return &ConstantCondition{Value: val}, nil
		}
		return nil, errors.Errorf("unsupported call expression %q", call.Function)
	}
}

func buildComparisonCondition(call *exprv1.Expr_Call, pc parseContext) (Condition, error) {
	if len(call.Args) != 2 {
		return nil, errors.New("comparison expects two arguments")
	}
	op, err := toComparisonOperator(call.Function)
	if err != nil {
		return nil, err
	}

	left, err := buildValueExpr(call.Args[0], pc)
	if err != nil {
		return nil, err
	}
	right, err := buildValueExpr(call.Args[1], pc)
	if err != nil {
		return nil, err
	}

	// The renderer expects a field/function/accessor on the left. A folded
	// literal on the left (e.g. now.getMonth() == created_ts.getMonth()) swaps
	// operands; two literals fold to a constant outcome.

View on GitHub (pinned to 14d757ce1f)

Solutions

  1. Write comparisons in plain binary form: pinned == true, created_ts < 1234567890.
  2. If constructing ASTs directly, always emit comparison calls with exactly two args.
  3. Report as an engine bug if a hand-written filter triggers it.

Example fix

# before (generated AST misuse)

# after
pinned == true
Defensive patterns

Strategy: validation

Validate before calling

// Go — always emit 'field <op> value' pairs when generating comparisons
func cmp(field, op string, v any) string { return fmt.Sprintf("%s %s %v", field, op, v) }

Try / catch

if err != nil && strings.Contains(err.Error(), "comparison expects two arguments") {
  return errors.Wrap(err, "internal filter AST inconsistency; report with the filter text")
}

Prevention

When it happens

Trigger: A parsed comparison Expr_Call with arity != 2 — possible via programmatic AST construction, macro desugaring edge cases, or corrupted parsed expressions; not from a normal hand-written comparison.

Common situations: Code that synthesizes filter ASTs; parser tests; effectively unreachable through the public Compile(string) path with well-formed input.

Related errors


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