toeverything/AFFiNE · warning · QueryTooLong

query_too_long

query_too_long

Error message

Query is too long, max length is ${max}.

What it means

Thrown when searching workspace members with a query longer than 255 characters. The hard cap is fixed at 255 in the realtime member-search resolver.

Source

Thrown at packages/backend/server/src/core/workspaces/realtime.ts:330

      workspaceId: string;
      skip?: number;
      take?: number;
      query?: string;
    }
  ) {
    await this.assertMembersRead(user.id, input.workspaceId);

    const pagination = {
      offset: Math.max(input.skip ?? 0, 0),
      first: Math.min(
        Math.max(input.take ?? 8, 1),
        WORKSPACE_MEMBERS_REQUEST_TAKE_MAX
      ),
    };

    if (input.query) {
      if (input.query.length > 255) {
        throw new QueryTooLong({ max: 255 });
      }
      const members = await this.models.workspaceUser.search(
        input.workspaceId,
        input.query,
        pagination
      );
      return {
        members: members.map(serializeWorkspaceMember),
        memberCount: await this.models.workspaceUser.count(input.workspaceId),
      };
    }

    const [members, memberCount] = await this.models.workspaceUser.paginate(
      input.workspaceId,
      pagination
    );
    return {
      members: members.map(serializeWorkspaceMember),

View on GitHub (pinned to 26c515e050)

Solutions

  1. Limit the search input to 255 characters on the client (maxLength=255).
  2. Trim/truncate the query before sending.
  3. Validate length before calling the resolver.

Example fix

// before
<input onChange={e => search(e.target.value)} />
// after
<input maxLength={255} onChange={e => search(e.target.value.trim().slice(0, 255))} />
Defensive patterns

Strategy: validation

Validate before calling

const QUERY_MAX = 255
function safeQuery(q: string) {
  return q.trim().slice(0, QUERY_MAX)
}

Type guard

function isValidMemberQuery(q: string): boolean { return q.trim().length <= 255 }

Try / catch

try { await searchMembers(ws, q) } catch (e) {
  if (e.code === 'query_too_long') searchMembers(ws, q.slice(0, 255))
  else throw e
}

Prevention

When it happens

Trigger: Calling the workspace member search with input.query.length > 255 (e.g. pasting a very long string, a search box without maxlength).

Common situations: No client-side maxlength on the search input; pasting a document by accident; programmatic search with unbounded input.

Related errors


AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12). Data as JSON: /api/errors/f270b1a5f0f8b613. Report an issue: GitHub.