Skip to content

Commit

Permalink
[ENG-4975] pass InvalidCursor down to the client (#32315)
Browse files Browse the repository at this point in the history
InvalidCursor gets obfuscated in prod, so usePaginatedQuery throws on bounds change.
To fix, we throw a ConvexError so it doesn't get obfuscated.

GitOrigin-RevId: dbe2df7163a524b5b16ec80a38a755cf96f22eb4
  • Loading branch information
ldanilek authored and Convex, Inc. committed Dec 19, 2024
1 parent 49384b8 commit a235a98
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/react/use_paginated_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
paginationOptsValidator,
PaginationResult,
} from "../server/index.js";
import { convexToJson, Infer, Value } from "../values/index.js";
import { ConvexError, convexToJson, Infer, Value } from "../values/index.js";
import { useQueries } from "./use_queries.js";
import {
FunctionArgs,
Expand Down Expand Up @@ -247,7 +247,13 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
}

if (currResult instanceof Error) {
if (currResult.message.includes("InvalidCursor")) {
if (
currResult.message.includes("InvalidCursor") ||
(currResult instanceof ConvexError &&
typeof currResult.data === "object" &&
currResult.data?.isConvexSystemError === true &&
currResult.data?.paginationError === "InvalidCursor")
) {
// - InvalidCursor: If the cursor is invalid, probably the paginated
// database query was data-dependent and changed underneath us. The
// cursor in the params or journal no longer matches the current
Expand Down

0 comments on commit a235a98

Please sign in to comment.