{"record":{"id":"83124ef7e81c2040","repo":"usememos/memos","slug":"endswith-argument-must-be-a-string","errorCode":null,"errorMessage":"endsWith argument must be a string","messagePattern":"endsWith argument must be a string","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"internal/filter/parser.go","lineNumber":993,"sourceCode":"\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 {\n\t\treturn nil, errors.Errorf(\"contains target must be the iteration variable %q\", iterVar)\n\t}\n\n\tif len(call.Args) != 1 {\n\t\treturn nil, errors.New(\"contains expects exactly one argument\")\n\t}\n\n\tsubstring, err := getConstValue(call.Args[0])\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"contains argument must be a constant string\")","sourceCodeStart":975,"sourceCodeEnd":1011,"githubUrl":"https://github.com/usememos/memos/blob/14d757ce1fb31c78590f374bc042f8dbedbc20d7/internal/filter/parser.go#L975-L1011","documentation":"The argument to endsWith() in a comprehension predicate must be a compile-time string constant. A constant of any other type (int, bool, timestamp, ...) triggers this error; non-constant operands surface as the wrapped 'endsWith argument must be a constant string'.","triggerScenarios":"tag.exists(t, t.endsWith(2024)) or tag.all(t, t.endsWith(true)) — non-string literal passed to endsWith.","commonSituations":"Unquoted suffix values; users copying numeric suffix patterns from docs of other systems.","solutions":["Quote the suffix: tag.exists(t, t.endsWith(\".draft\"))","Check the field is a string list before using endsWith"],"exampleFix":"// before\n`tag.exists(t, t.endsWith(2024))`\n\n// after\n`tag.exists(t, t.endsWith(\".draft\"))`","handlingStrategy":"validation","validationCode":"var badEndsWith = regexp.MustCompile(`endsWith\\s*\\(\\s*[^\"']`)\n\nfunc validateEndsWith(expr string) error {\n    if badEndsWith.MatchString(expr) {\n        return errors.New(\"endsWith needs a quoted string suffix\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := r.Render(cond); err != nil {\n    if strings.Contains(err.Error(), \"endsWith argument must be a string\") {\n        return userErr(\"quote the endsWith suffix, e.g. t.endsWith(\\\".draft\\\")\")\n    }\n    return err\n}","preventionTips":["Quote suffix literals","Keep suffixes as plain strings, not numeric or boolean literals"],"tags":["cel","filter","parser","comprehension","type-mismatch"],"backgroundTag":null,"analyzedSha":"14d757ce1fb31c78590f374bc042f8dbedbc20d7","analyzedAt":"2026-08-15T09:27:36.538Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}