{"record":{"id":"61788104493897f0","repo":"usememos/memos","slug":"size-argument-must-be-a-field","errorCode":null,"errorMessage":"size() argument must be a field","messagePattern":"size\\(\\) argument must be a field","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"internal/filter/render.go","lineNumber":266,"sourceCode":"\tdefault:\n\t\treturn \"\", errors.Errorf(\"unsupported dialect %q\", r.dialect)\n\t}\n\tif off != 0 {\n\t\tbase = fmt.Sprintf(\"(%s - %d)\", base, off)\n\t}\n\treturn base, nil\n}\n\nfunc (r *renderer) renderFunctionComparison(fn *FunctionValue, op ComparisonOperator, right ValueExpr) (renderResult, error) {\n\tif fn.Name != \"size\" {\n\t\treturn renderResult{}, errors.Errorf(\"unsupported function %s in comparison\", fn.Name)\n\t}\n\tif len(fn.Args) != 1 {\n\t\treturn renderResult{}, errors.New(\"size() expects one argument\")\n\t}\n\tfieldArg, ok := fn.Args[0].(*FieldRef)\n\tif !ok {\n\t\treturn renderResult{}, errors.New(\"size() argument must be a field\")\n\t}\n\n\tfield, ok := r.schema.Field(fieldArg.Name)\n\tif !ok {\n\t\treturn renderResult{}, errors.Errorf(\"unknown field %q\", fieldArg.Name)\n\t}\n\tif field.Kind == FieldKindVirtualAlias {\n\t\tfield, ok = r.schema.ResolveAlias(fieldArg.Name)\n\t\tif !ok {\n\t\t\treturn renderResult{}, errors.Errorf(\"invalid alias %q\", fieldArg.Name)\n\t\t}\n\t}\n\n\tvalue, err := expectNumericLiteral(right)\n\tif err != nil {\n\t\treturn renderResult{}, err\n\t}\n","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/usememos/memos/blob/14d757ce1fb31c78590f374bc042f8dbedbc20d7/internal/filter/render.go#L248-L284","documentation":"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.","triggerScenarios":"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.","commonSituations":"Users test size() with inline literals before using real fields; copy filters from contexts where size works on arbitrary expressions.","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()"],"exampleFix":"// before\n`size(\"hello\") > 3`\n\n// after\n`size(tag) > 2`","handlingStrategy":"type-guard","validationCode":"if _, ok := fn.Args[0].(*filter.FieldRef); !ok {\n    return errors.New(\"size() must wrap a field reference\")\n}","typeGuard":"func isSizeOnField(fn *filter.FunctionValue) bool {\n    arg, ok := fn.Args[0].(*filter.FieldRef)\n    return ok && arg != nil\n}","tryCatchPattern":"if err := r.Render(cond); err != nil {\n    if strings.Contains(err.Error(), \"size() argument must be a field\") {\n        return userErr(\"apply size() to a field, e.g. size(tag)\")\n    }\n    return err\n}","preventionTips":["Apply size() only to schema fields, never to literals or nested calls","Check the field exists in the schema before using size()"],"tags":["cel","filter","renderer","sql","size-function"],"backgroundTag":null,"analyzedSha":"14d757ce1fb31c78590f374bc042f8dbedbc20d7","analyzedAt":"2026-08-15T09:27:36.538Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}