usememos/memos · error

duration() expects one argument

Error message

duration() expects one argument

What it means

evaluateDuration folds duration("<go-duration>") into an integer number of seconds, enabling expressions like created_ts > now - duration("24h"). It first requires exactly one argument; zero or multiple arguments fail here.

Source

Thrown at internal/filter/parser.go:616

	}
	switch v := value.(type) {
	case string:
		ts, err := time.Parse(time.RFC3339, v)
		if err != nil {
			return 0, false, errors.Wrap(err, "invalid timestamp literal")
		}
		return ts.Unix(), true, nil
	case int64:
		return v, true, nil
	default:
		return 0, false, errors.New("timestamp() argument must be an RFC3339 string or epoch int")
	}
}

// evaluateDuration folds duration("<go-duration>") into a number of seconds.
func evaluateDuration(call *exprv1.Expr_Call) (int64, bool, error) {
	if len(call.Args) != 1 {
		return 0, false, errors.New("duration() expects one argument")
	}
	value, err := getConstValue(call.Args[0])
	if err != nil {
		return 0, false, errors.Wrap(err, "duration() only supports literal arguments")
	}
	str, ok := value.(string)
	if !ok {
		return 0, false, errors.New("duration() argument must be a string")
	}
	d, err := time.ParseDuration(str)
	if err != nil {
		return 0, false, errors.Wrap(err, "invalid duration literal")
	}
	return int64(d.Seconds()), true, nil
}

// timestampAccessors is the set of supported CEL timestamp accessor methods.
var timestampAccessors = map[string]bool{

View on GitHub (pinned to 14d757ce1f)

Solutions

  1. Pass one Go duration string: duration("24h")
  2. Combine spans inside the string: duration("1h30m")
  3. Add two duration() calls with + if needed

Example fix

// before
now - duration("24h", "30m")

// after
now - duration("24h30m")
Defensive patterns

Strategy: validation

Validate before calling

// Go: validate a Go duration string before templating
if _, err := time.ParseDuration(d); err != nil {
    return errors.Wrap(err, "invalid duration")
}

Type guard

func isGoDuration(s string) bool { _, err := time.ParseDuration(s); return err == nil }

Prevention

When it happens

Trigger: Filters like created_ts > now - duration() or duration("24h", "1h") — any duration() call whose argument count is not 1.

Common situations: Trying to sum multiple durations as separate arguments instead of adding them; template variable that expands empty for the duration string.

Related errors


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