fix: handle Convex InvalidCursor and align backend config

This commit is contained in:
Esdras Renan 2025-11-17 23:53:43 -03:00
parent 3565500e9c
commit 07a6f101b8
6 changed files with 44 additions and 9 deletions

View file

@ -233,7 +233,39 @@ async function paginateTickets<T>(
return;
}
const page: PaginatedResult<T> = await paginateFn.call(query, { cursor, numItems: pageSize });
let page: PaginatedResult<T>;
try {
page = await paginateFn.call(query, { cursor, numItems: pageSize });
} catch (error) {
// Em cenários raros o Convex pode lançar InvalidCursor quando
// o fingerprint da query muda entre páginas. Nesse caso,
// fazemos fallback para uma leitura simples via collect()
// para evitar quebrar o dashboard.
const message = (error as Error | null | undefined)?.message ?? "";
const isInvalidCursor =
typeof message === "string" &&
message.includes("InvalidCursor");
// Alguns erros de paginação vêm embrulhados em ConvexError com metadados.
const data = (error as any)?.data;
const isPaginationInvalidCursor =
data && typeof data === "object" && data.paginationError === "InvalidCursor";
if (isInvalidCursor || isPaginationInvalidCursor) {
const fallbackQuery = buildQuery();
const collectFn = fallbackQuery.collect;
if (typeof collectFn !== "function") {
throw error;
}
const docs = await collectFn.call(fallbackQuery);
for (const doc of docs) {
await handler(doc);
}
return;
}
throw error;
}
for (const doc of page.page) {
await handler(doc);
}