From c0ff7c71b68f61a1307b95ae85e8a8a8a264349a Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Wed, 4 Nov 2026 14:41:05 +0000 Subject: [PATCH] Sync: a deleted item's NOT_FOUND reads as null instead of failing the run --- src/mirror.ts | 5 ++++- test/mirror.test.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mirror.ts b/src/mirror.ts index 0313471d..33983984 100644 --- a/src/mirror.ts +++ b/src/mirror.ts @@ -129,7 +129,10 @@ export class Client { if (/node_limit|resource_limits|timeout|something went wrong/.test(r.text)) throw new Transient("query too heavy"); throw new Error(`graphql error: ${JSON.stringify(r.errors).slice(0, 500)}`); } - if (r.failed) { + // A deleted or transferred item is a NOT_FOUND error beside a null field, and gh exits non-zero; with the repository + // present the answer is that null field, which callers handle. + const missingOnly = r.errors.length > 0 && r.errors.every((e: Node) => e.type === "NOT_FOUND") && !!r.data?.repository; + if (r.failed && !missingOnly) { if (/502|503|504|timeout|eof|connection|unexpected end of json/.test(r.text)) throw new Transient(r.stderr.trim().slice(0, 200)); throw new Error(`gh failed: ${r.stderr.trim().slice(0, 500)}`); } diff --git a/test/mirror.test.ts b/test/mirror.test.ts index 0be6f378..32c0bb36 100644 --- a/test/mirror.test.ts +++ b/test/mirror.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -import { untilCutoff } from "../src/mirror.ts"; +import { Client, untilCutoff } from "../src/mirror.ts"; import { validating } from "./gql.ts"; const page = (...times: string[]) => times.map((updatedAt) => ({ updatedAt })); @@ -140,3 +140,12 @@ test("sync stores the text hashes the planner compares", async () => { + +test("a deleted item reads as null; a missing repository still fails", async () => { + const c = new Client(0); + const answer = (data: unknown) => () => ({ data, errors: [{ type: "NOT_FOUND", message: "Could not resolve to an issue or pull request with the number of 2401." }], text: "", failed: true, stderr: "gh: Could not resolve" }); + (c as unknown as { run: unknown }).run = answer({ rateLimit: { cost: 1, remaining: 4000, resetAt: "2026-11-04T15:00:00Z" }, repository: { issueOrPullRequest: null } }); + assert.equal((await c.query("q", {})).repository.issueOrPullRequest, null); + (c as unknown as { run: unknown }).run = answer({ repository: null }); + await assert.rejects(c.query("q", {})); +});