usememos/memos · error

InvalidArgument

InvalidArgument

Error message

empty order_by

What it means

parseMemoOrderBy implements AIP-132 style ordering for ListMemos: it splits the order_by string on commas and parses each field with optional ASC/DESC direction. An order_by that is empty or only whitespace is rejected up front as InvalidArgument, because there is no field to sort by.

Source

Thrown at server/router/api/v1/memo_service_query.go:13

package v1

import (
	"strings"

	"github.com/pkg/errors"

	"github.com/usememos/memos/store"
)

func (*APIV1Service) parseMemoOrderBy(orderBy string, memoFind *store.FindMemo) error {
	if strings.TrimSpace(orderBy) == "" {
		return errors.New("empty order_by")
	}

	// Split by comma to support multiple sort fields per AIP-132.
	fields := strings.Split(orderBy, ",")

	// Track if we've seen pinned field.
	hasPinned := false
	hasExplicitTimeField := false

	for _, field := range fields {
		parts := strings.Fields(strings.TrimSpace(field))
		if len(parts) == 0 {
			continue
		}

		fieldName := parts[0]
		fieldDirection := "desc" // default per AIP-132 (we use desc as default for time fields)
		if len(parts) > 1 {

View on GitHub (pinned to 14d757ce1f)

Solutions

  1. Omit order_by entirely when the user has not chosen a sort (server default applies), or send a valid field like 'display_ts DESC'.
  2. Guard in the client: if (!orderBy.trim()) delete request.orderBy.
  3. Check supported field names/directions in memo_service_query.go if a non-empty value is also rejected downstream.

Example fix

// before
const resp = await memoClient.listMemos({ orderBy: sortBy }); // sortBy = ''

// after
const req = { pageSize: 50 };
if (sortBy.trim()) req.orderBy = sortBy; // e.g. 'display_ts DESC'
const resp = await memoClient.listMemos(req);
Defensive patterns

Strategy: validation

Validate before calling

if (orderBy !== undefined && !orderBy.trim()) {
  throw new Error('order_by must be non-empty when provided');
}

Prevention

When it happens

Trigger: ListMemos(request.order_by = ''), order_by = ' ', a UI sort control reset to blank but still serialized into the request, or a client defaulting the field to an empty string.

Common situations: Frontend state where 'sort by' is optional and empty string leaks into the RPC; scripts copying request templates and blanking sort; upgrades that changed order_by from optional to validated.

Related errors


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