toeverything/AFFiNE · warning · QueryTooLong

query_too_long

query_too_long

Error message

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

What it means

Thrown by the admin shared-links analytics list (workspace-analytics.ts:572) when the search keyword exceeds DOC_MEMBER_QUERY_MAX_LENGTH (255). The check runs after trimming and protects the downstream ILIKE query from pathological inputs. UserFriendlyError QueryTooLong, code query_too_long, type invalid_input, HTTP 400, data {max:255}.

Source

Thrown at packages/backend/server/src/models/workspace-analytics.ts:572

      generatedAt: now,
    };
  }

  async adminPaginateAllSharedLinks(
    options: AdminAllSharedLinksOptions
  ): Promise<
    OptionalTotalPaginated<AdminSharedLinkNode> & {
      analyticsWindow: TimeWindowDto;
    }
  > {
    const pagination: PaginationInput = {
      ...options.pagination,
      first: Math.min(Math.max(options.pagination.first ?? 10, 1), 100),
      offset: Math.max(options.pagination.offset ?? 0, 0),
    };
    const keyword = options.keyword?.trim();
    if (keyword && keyword.length > DOC_MEMBER_QUERY_MAX_LENGTH) {
      throw new QueryTooLong({ max: DOC_MEMBER_QUERY_MAX_LENGTH });
    }

    const includeTotal = options.includeTotal ?? false;
    const orderBy = options.orderBy ?? 'UpdatedAtDesc';
    const analyticsWindowDays = clampInt(
      options.analyticsWindowDays,
      1,
      90,
      DEFAULT_ANALYTICS_WINDOW_DAYS
    );
    const now = new Date();
    const currentDay = startOfUtcDay(now);
    const analyticsFrom = addUtcDays(currentDay, -(analyticsWindowDays - 1));

    const cursor = parseJsonCursor<SharedLinkCursor>(pagination.after ?? null);
    const cursorCondition = this.buildSharedLinkCursorCondition(
      orderBy,
      cursor

View on GitHub (pinned to 26c515e050)

Solutions

  1. Trim and shorten the keyword to <=255 characters before sending.
  2. Validate the length client-side and disable submit when exceeded.
  3. If a broader search is needed, use a dedicated filter/export endpoint instead of the keyword param.

Example fix

// before
const keyword = rawInput;
// after
const keyword = rawInput.trim().slice(0, 255);
Defensive patterns

Strategy: validation

Validate before calling

const DOC_MEMBER_QUERY_MAX_LENGTH = 255;
function safeKeyword(input: string): string {
  return input.trim().slice(0, DOC_MEMBER_QUERY_MAX_LENGTH);
}

Try / catch

import { QueryTooLong } from '../base/error/errors.gen';

try {
  await models.workspaceAnalytics.adminListSharedLinks({ keyword, ... });
} catch (e) {
  if (e instanceof QueryTooLong) {
    // shorten the keyword and retry
  } else throw e;
}

Prevention

When it happens

Trigger: GET on the admin analytics shared-links endpoint with ?keyword longer than 255 characters.

Common situations: User pastes a large blob into the search box; an automated client omits a length clamp; adversarial/long input sent to probe limits.

Related errors


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