mirror of
https://github.com/storytold/autocraft.git
synced 2026-11-24 00:11:08 +01:00
Sync: a deleted item's NOT_FOUND reads as null instead of failing the run
This commit is contained in:
1 parent
dfd88b86a3
commit
c0ff7c71b6
2 files changed
+14
-2
No files matched your search
+4
-1
@@ -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)}`);
|
||||
}
|
||||
|
||||
+10
-1
@@ -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", {}));
|
||||
});
|
||||
Reference in new issue
Block a user