usememos/memos · error
boolean literal required
Error message
boolean literal required
What it means
Thrown by expectBool in the filter renderer when a boolean-only construct (e.g. `pinned` comparisons or boolean flags) receives a literal that is not a Go bool. The parser accepted it as a literal node, but the type assertion lit.(bool) failed, so the filter cannot be rendered to SQL.
Source
Thrown at internal/filter/render.go:862
return r.addArg(v)
}
func expectLiteral(expr ValueExpr) (any, error) {
lit, ok := expr.(*LiteralValue)
if !ok {
return nil, errors.New("expression must be a literal")
}
return lit.Value, nil
}
func expectBool(expr ValueExpr) (bool, error) {
lit, err := expectLiteral(expr)
if err != nil {
return false, err
}
value, ok := lit.(bool)
if !ok {
return false, errors.New("boolean literal required")
}
return value, nil
}
func expectNumericLiteral(expr ValueExpr) (int64, error) {
lit, err := expectLiteral(expr)
if err != nil {
return 0, err
}
return toInt64(lit)
}
func toInt64(value any) (int64, error) {
switch v := value.(type) {
case int:
return int64(v), nil
case int32:
return int64(v), nilView on GitHub (pinned to 14d757ce1f)
Solutions
- Use bare boolean literals: `pinned == true` not `pinned == "true"`
- Fix the client code that stringifies booleans before building filter strings
- Validate filter strings against the engine (CompileToStatement) before saving them
Example fix
// before filter := `pinned == "true"` // after filter := `pinned == true`
Defensive patterns
Strategy: validation
Validate before calling
// Ensure boolean positions get bare true/false, not quoted strings or numbers
var quotedBool = regexp.MustCompile(`==\s*"(?:true|false)"`)
func hasQuotedBoolean(filter string) bool { return quotedBool.MatchString(filter) } Type guard
func isBoolLiteral(v any) bool { _, ok := v.(bool); return ok } Try / catch
// Wrap compile; map 'boolean literal required' to a user-facing message with the offending fragment
if _, err := engine.CompileToStatement(ctx, filter, opts); err != nil {
if strings.Contains(err.Error(), "boolean literal required") {
return errors.New("use bare true/false without quotes in the filter")
}
return err
} Prevention
- Never stringify booleans when constructing filters
- Keep a shared filter-builder that emits typed literals
- Test saved filters in a filter playground before use
When it happens
Trigger: Filters like `pinned == "true"`, `pinned == 1`, or `pinned in [true, "false"]` where the boolean position gets a string or numeric literal.
Common situations: Frontends or scripts serializing booleans as strings (JSON query params), users quoting boolean values out of habit, or porting filters from a dialect where truthy coercion exists.
Related errors
- filter expression is empty
- filter must evaluate to a boolean value
- invalid use of in operator
- text match expects exactly one argument
- tags membership requires string literal
AI-assisted analysis of usememos/memos@14d757ce1f (2026-08-15).
Data as JSON: /api/errors/5450bd89cbb7e29f.
Report an issue: GitHub.