{"record":{"id":"f270b1a5f0f8b613","repo":"toeverything/AFFiNE","slug":"query-too-long","errorCode":"query_too_long","errorMessage":"Query is too long, max length is ${max}.","messagePattern":"Query is too long, max length is (.+?)\\.","errorType":"exception","errorClass":"QueryTooLong","httpStatus":400,"severity":"warning","filePath":"packages/backend/server/src/core/workspaces/realtime.ts","lineNumber":330,"sourceCode":"      workspaceId: string;\n      skip?: number;\n      take?: number;\n      query?: string;\n    }\n  ) {\n    await this.assertMembersRead(user.id, input.workspaceId);\n\n    const pagination = {\n      offset: Math.max(input.skip ?? 0, 0),\n      first: Math.min(\n        Math.max(input.take ?? 8, 1),\n        WORKSPACE_MEMBERS_REQUEST_TAKE_MAX\n      ),\n    };\n\n    if (input.query) {\n      if (input.query.length > 255) {\n        throw new QueryTooLong({ max: 255 });\n      }\n      const members = await this.models.workspaceUser.search(\n        input.workspaceId,\n        input.query,\n        pagination\n      );\n      return {\n        members: members.map(serializeWorkspaceMember),\n        memberCount: await this.models.workspaceUser.count(input.workspaceId),\n      };\n    }\n\n    const [members, memberCount] = await this.models.workspaceUser.paginate(\n      input.workspaceId,\n      pagination\n    );\n    return {\n      members: members.map(serializeWorkspaceMember),","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/packages/backend/server/src/core/workspaces/realtime.ts#L312-L348","documentation":"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.","triggerScenarios":"Calling the workspace member search with input.query.length > 255 (e.g. pasting a very long string, a search box without maxlength).","commonSituations":"No client-side maxlength on the search input; pasting a document by accident; programmatic search with unbounded input.","solutions":["Limit the search input to 255 characters on the client (maxLength=255).","Trim/truncate the query before sending.","Validate length before calling the resolver."],"exampleFix":"// before\n<input onChange={e => search(e.target.value)} />\n// after\n<input maxLength={255} onChange={e => search(e.target.value.trim().slice(0, 255))} />","handlingStrategy":"validation","validationCode":"const QUERY_MAX = 255\nfunction safeQuery(q: string) {\n  return q.trim().slice(0, QUERY_MAX)\n}","typeGuard":"function isValidMemberQuery(q: string): boolean { return q.trim().length <= 255 }","tryCatchPattern":"try { await searchMembers(ws, q) } catch (e) {\n  if (e.code === 'query_too_long') searchMembers(ws, q.slice(0, 255))\n  else throw e\n}","preventionTips":["Set maxlength on search inputs.","Trim/normalize query text.","Validate before network calls."],"tags":["input-validation","search","pagination","realtime"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}