From b276a5ce0f882fc4dc6f85ed371c802584317e3b Mon Sep 17 00:00:00 2001 From: Alan Daniel Date: Sun, 12 Apr 2026 17:58:29 -0400 Subject: [PATCH] Handle undefined pull page data --- apps/dashboard/src/lib/github.query.ts | 7 ++++++- apps/dashboard/src/lib/query-data.test.ts | 19 +++++++++++++++++++ apps/dashboard/src/lib/query-data.ts | 11 +++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 apps/dashboard/src/lib/query-data.test.ts create mode 100644 apps/dashboard/src/lib/query-data.ts diff --git a/apps/dashboard/src/lib/github.query.ts b/apps/dashboard/src/lib/github.query.ts index 5ffd4d8..546aa84 100644 --- a/apps/dashboard/src/lib/github.query.ts +++ b/apps/dashboard/src/lib/github.query.ts @@ -36,6 +36,7 @@ import { searchCommandPaletteGitHub, } from "./github.functions"; import { githubCachePolicy } from "./github-cache-policy"; +import { ensureDefinedQueryData } from "./query-data"; type RepoState = "all" | "closed" | "open"; type PullSort = "created" | "long-running" | "popularity" | "updated"; @@ -302,7 +303,11 @@ export function githubPullPageQueryOptions( ) { return queryOptions({ queryKey: githubQueryKeys.pulls.page(scope, input), - queryFn: () => getPullPageData({ data: input }), + queryFn: () => + ensureDefinedQueryData( + () => getPullPageData({ data: input }), + "getPullPageData", + ), staleTime: githubCachePolicy.detail.staleTimeMs, gcTime: githubCachePolicy.detail.gcTimeMs, meta: tabPersistedMeta, diff --git a/apps/dashboard/src/lib/query-data.test.ts b/apps/dashboard/src/lib/query-data.test.ts new file mode 100644 index 0000000..335b3b6 --- /dev/null +++ b/apps/dashboard/src/lib/query-data.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it, vi } from "vitest"; +import { ensureDefinedQueryData } from "./query-data"; + +describe("ensureDefinedQueryData", () => { + it("passes through null because null is intentional query data", async () => { + await expect( + ensureDefinedQueryData(async () => null, "getNullableData"), + ).resolves.toBeNull(); + }); + + it("throws when a query loader resolves undefined", async () => { + const load = vi.fn(async () => undefined); + + await expect( + ensureDefinedQueryData(load, "getPullPageData"), + ).rejects.toThrow("getPullPageData returned undefined"); + expect(load).toHaveBeenCalledTimes(1); + }); +}); diff --git a/apps/dashboard/src/lib/query-data.ts b/apps/dashboard/src/lib/query-data.ts new file mode 100644 index 0000000..99c26bf --- /dev/null +++ b/apps/dashboard/src/lib/query-data.ts @@ -0,0 +1,11 @@ +export async function ensureDefinedQueryData( + load: () => Promise, + source: string, +): Promise> { + const data = await load(); + if (typeof data === "undefined") { + throw new Error(`${source} returned undefined`); + } + + return data as Exclude; +}