usememos/memos · error

size() expects one argument

Error message

size() expects one argument

What it means

renderFunctionComparison supports only size(), and requires it to have exactly one argument. A FunctionValue named size with zero or multiple args cannot name a field to measure and fails here.

Source

Thrown at internal/filter/render.go:262

		off = spec.off[1]
	case DialectMySQL:
		base = fmt.Sprintf("%s(%s)", spec.mysql, col)
		off = spec.off[2]
	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)

View on GitHub (pinned to 14d757ce1f)

Solutions

  1. Use the textual form size(field) or field.size(), e.g. content.size() > 100
  2. When constructing FunctionValue programmatically, pass exactly one FieldRef argument
Defensive patterns

Strategy: type-guard

Validate before calling

if fn.Name == "size" && len(fn.Args) != 1 {
    return errors.New("size() takes exactly one field argument")
}

Type guard

func isValidSizeCall(fn *filter.FunctionValue) bool {
    return fn.Name == "size" && len(fn.Args) == 1
}

Try / catch

if err := validateFn(fn); err != nil {
    return fmt.Errorf("invalid size() usage: %w", err)
}

Prevention

When it happens

Trigger: Programmatically built FunctionValue{Name:"size", Args: []} or Args with 2+ entries; textual CEL's size(x) macro always emits one arg, so this fires on malformed ASTs or direct condition construction.

Common situations: Custom ValueExpr/FunctionValue construction in code that reuses the renderer; tests building conditions by hand.

Related errors


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