{"record":{"id":"69a790769d7776cc","repo":"usememos/memos","slug":"endswith-expects-exactly-one-argument","errorCode":null,"errorMessage":"endsWith expects exactly one argument","messagePattern":"endsWith expects exactly one argument","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"internal/filter/parser.go","lineNumber":983,"sourceCode":"\t\treturn nil, errors.Wrap(err, \"startsWith argument must be a constant string\")\n\t}\n\n\tprefixStr, ok := prefix.(string)\n\tif !ok {\n\t\treturn nil, errors.New(\"startsWith argument must be a string\")\n\t}\n\n\treturn &StartsWithPredicate{Prefix: prefixStr}, nil\n}\n\n// buildEndsWithPredicate extracts the pattern from t.endsWith(\"suffix\").\nfunc buildEndsWithPredicate(call *exprv1.Expr_Call, iterVar string) (PredicateExpr, error) {\n\tif target := call.Target.GetIdentExpr(); target == nil || target.GetName() != iterVar {\n\t\treturn nil, errors.Errorf(\"endsWith target must be the iteration variable %q\", iterVar)\n\t}\n\n\tif len(call.Args) != 1 {\n\t\treturn nil, errors.New(\"endsWith expects exactly one argument\")\n\t}\n\n\tsuffix, err := getConstValue(call.Args[0])\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"endsWith argument must be a constant string\")\n\t}\n\n\tsuffixStr, ok := suffix.(string)\n\tif !ok {\n\t\treturn nil, errors.New(\"endsWith argument must be a string\")\n\t}\n\n\treturn &EndsWithPredicate{Suffix: suffixStr}, nil\n}\n\n// buildContainsPredicate extracts the pattern from t.contains(\"substring\").\nfunc buildContainsPredicate(call *exprv1.Expr_Call, iterVar string) (PredicateExpr, error) {\n\tif target := call.Target.GetIdentExpr(); target == nil || target.GetName() != iterVar {","sourceCodeStart":965,"sourceCodeEnd":1001,"githubUrl":"https://github.com/usememos/memos/blob/14d757ce1fb31c78590f374bc042f8dbedbc20d7/internal/filter/parser.go#L965-L1001","documentation":"buildEndsWithPredicate translates t.endsWith(\"suffix\") and requires exactly one argument after confirming the target is the iteration variable. Wrong arity is rejected here.","triggerScenarios":"Programmatically built endsWith call with 0 or 2+ args; not reachable from textual CEL, which always passes one argument.","commonSituations":"Direct AST construction in tests or custom macro pipelines.","solutions":["Use the textual form tag.exists(t, t.endsWith(\"work\"))","Emit exactly one argument for endsWith when constructing Expr_Call nodes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := r.Render(cond); err != nil {\n    if strings.Contains(err.Error(), \"endsWith expects exactly one argument\") {\n        return errors.New(\"call endsWith with a single quoted suffix\")\n    }\n    return err\n}","preventionTips":["Pass exactly one string argument to endsWith","Use textual method syntax t.endsWith(\"...\")"],"tags":["cel","filter","parser","comprehension","string-ops"],"backgroundTag":null,"analyzedSha":"14d757ce1fb31c78590f374bc042f8dbedbc20d7","analyzedAt":"2026-08-15T09:27:36.538Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}