usememos/memos · error
size() argument must be a field
Error message
size() argument must be a field
What it means
size() must be applied directly to a field reference. If its single argument is a literal, accessor, or nested function instead of a *FieldRef, the renderer cannot resolve a column to measure and returns this error.
Source
Thrown at internal/filter/render.go:266
default:
return "", errors.Errorf("unsupported dialect %q", r.dialect)
}
if off != 0 {
base = fmt.Sprintf("(%s - %d)", base, off)
}
return base, nil
}
func (r *renderer) renderFunctionComparison(fn *FunctionValue, op ComparisonOperator, right ValueExpr) (renderResult, error) {
if fn.Name != "size" {
return renderResult{}, errors.Errorf("unsupported function %s in comparison", fn.Name)
}
if len(fn.Args) != 1 {
return renderResult{}, errors.New("size() expects one argument")
}
fieldArg, ok := fn.Args[0].(*FieldRef)
if !ok {
return renderResult{}, errors.New("size() argument must be a field")
}
field, ok := r.schema.Field(fieldArg.Name)
if !ok {
return renderResult{}, errors.Errorf("unknown field %q", fieldArg.Name)
}
if field.Kind == FieldKindVirtualAlias {
field, ok = r.schema.ResolveAlias(fieldArg.Name)
if !ok {
return renderResult{}, errors.Errorf("invalid alias %q", fieldArg.Name)
}
}
value, err := expectNumericLiteral(right)
if err != nil {
return renderResult{}, err
}
View on GitHub (pinned to 14d757ce1f)
Solutions
- Apply size to a schema field: size(tag) > 2 or content.size() > 100
- Check the field exists in the filter schema before using it with size()
Example fix
// before
`size("hello") > 3`
// after
`size(tag) > 2` Defensive patterns
Strategy: type-guard
Validate before calling
if _, ok := fn.Args[0].(*filter.FieldRef); !ok {
return errors.New("size() must wrap a field reference")
} Type guard
func isSizeOnField(fn *filter.FunctionValue) bool {
arg, ok := fn.Args[0].(*filter.FieldRef)
return ok && arg != nil
} Try / catch
if err := r.Render(cond); err != nil {
if strings.Contains(err.Error(), "size() argument must be a field") {
return userErr("apply size() to a field, e.g. size(tag)")
}
return err
} Prevention
- Apply size() only to schema fields, never to literals or nested calls
- Check the field exists in the schema before using size()
When it happens
Trigger: Textual CEL like size("hello") > 3 or size([1,2,3]) == 3 — calling size on a list/string literal rather than a schema field; also size(size(tag)) nesting.
Common situations: Users test size() with inline literals before using real fields; copy filters from contexts where size works on arbitrary expressions.
Related errors
- size() expects one argument
- comparison must start with a field reference or supported fu
- IN operator requires a field on the left-hand side
- tags must be compared with string literals
- tag attribute is not configured
AI-assisted analysis of usememos/memos@14d757ce1f (2026-08-15).
Data as JSON: /api/errors/61788104493897f0.
Report an issue: GitHub.