usememos/memos · error

invalid use of in operator

Error message

invalid use of in operator

What it means

Returned by buildInCondition's fallthrough when the @in call has 2 args but its shape matches neither supported form: 'identifier in list' nor 'value in identifier'. Both branches require Args[0] (or Args[1]) to resolve to a schema-known identifier; anything else (e.g., two list literals, or an identifier not in the schema and not a valid alias) ends here.

Source

Thrown at internal/filter/parser.go:308

		}
	}

	// Handle "value in identifier" syntax.
	if identName, err := getIdentName(call.Args[1]); err == nil {
		if _, ok := pc.schema.Field(identName); !ok {
			return nil, errors.Errorf("unknown identifier %q", identName)
		}
		element, err := buildValueExpr(call.Args[0], pc)
		if err != nil {
			return nil, err
		}
		return &ElementInCondition{
			Element: element,
			Field:   identName,
		}, nil
	}

	return nil, errors.New("invalid use of in operator")
}

func buildTextMatchCondition(call *exprv1.Expr_Call, schema Schema, mode TextMatchMode) (Condition, error) {
	if call.Target == nil {
		return nil, errors.New("text match requires a target")
	}
	targetName, err := getIdentName(call.Target)
	if err != nil {
		return nil, err
	}

	field, ok := schema.Field(targetName)
	if !ok {
		return nil, errors.Errorf("unknown identifier %q", targetName)
	}
	if !field.SupportsContains {
		return nil, errors.Errorf("identifier %q does not support text matching", targetName)
	}

View on GitHub (pinned to 14d757ce1f)

Solutions

  1. Put a known field on one side: tag in ["a"] or "a" in tag_list — check the schema for the exact identifier name.
  2. Fix typos in the identifier (unknown ones fail schema.Field lookup earlier with 'unknown identifier').
  3. Avoid list-in-list or expression-in-expression forms; they are unsupported.

Example fix

# before
[tags] in [["a"]]

# after
tag in ["a"]
Defensive patterns

Strategy: validation

Validate before calling

// Go — verify the identifier exists in the schema before compiling user filters
for _, id := range extractIdentifiers(filter) {
  if _, ok := schema.Field(id); !ok {
    return errors.Errorf("unknown identifier %q in filter", id)
  }
}
_, err := engine.Compile(ctx, filter)

Try / catch

if err != nil && strings.Contains(err.Error(), "invalid use of in operator") {
  return status.Errorf(codes.InvalidArgument, "use '<field> in [values]' or '<value> in <field>'")
}

Prevention

When it happens

Trigger: Filters like '[1,2] in [1,2]' (list in list) or 'unknownField in [...]' where the left side is neither a resolvable identifier nor paired with one on the right; also right-side non-identifier targets that earlier checks reject, leaving no valid branch.

Common situations: Typos in field names inside in-expressions; copied filters against a different schema where the field does not exist; over-clever expressions with computed values on both sides.

Related errors


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