fix: log Gitea transport failure causes

This commit is contained in:
2026-07-16 21:53:46 +02:00
parent 1988b8a7be
commit e12c11b8cb
3 changed files with 24 additions and 3 deletions
+4 -1
View File
@@ -95,7 +95,10 @@ export class GiteaTransport {
attempt === attempts - 1 || attempt === attempts - 1 ||
(!retryable && lastError instanceof GiteaHttpError) (!retryable && lastError instanceof GiteaHttpError)
) { ) {
throw lastError; if (lastError instanceof GiteaHttpError) throw lastError;
throw new Error(`${method} ${this.apiBase}${path} failed`, {
cause: lastError,
});
} }
} }
await abortableDelay(1_000 * 2 ** attempt, this.signal); await abortableDelay(1_000 * 2 ** attempt, this.signal);
+7 -1
View File
@@ -123,7 +123,13 @@ export function statusMarker(issue: number, mode: Mode): Marker {
} }
export function formatError(error: unknown): string { export function formatError(error: unknown): string {
if (error instanceof Error) return error.message; if (error instanceof Error) {
if (error.cause === undefined) return error.message;
const cause = formatError(error.cause);
return cause && cause !== error.message
? `${error.message}: ${cause}`
: error.message;
}
return String(error); return String(error);
} }
+13 -1
View File
@@ -6,13 +6,25 @@ import {
findAcceptedPlan, findAcceptedPlan,
} from "../../adapters/gitea/issues.js"; } from "../../adapters/gitea/issues.js";
import type { GiteaComment, GiteaIssue } from "../../adapters/gitea/types.js"; import type { GiteaComment, GiteaIssue } from "../../adapters/gitea/types.js";
import { marker, sha256 } from "../../core/contracts.js"; import { formatError, marker, sha256 } from "../../core/contracts.js";
import { import {
parseAgentCommand, parseAgentCommand,
parseCommentPayload, parseCommentPayload,
verifyGiteaSignature, verifyGiteaSignature,
} from "../../core/webhook.js"; } from "../../core/webhook.js";
test("formats nested transport error causes", () => {
const error = new Error("GET https://git.example/api/v1/user failed", {
cause: new TypeError("fetch failed", {
cause: new Error("getaddrinfo ENOTFOUND git.example"),
}),
});
assert.equal(
formatError(error),
"GET https://git.example/api/v1/user failed: fetch failed: getaddrinfo ENOTFOUND git.example",
);
});
test("verifies the raw Gitea HMAC signature", () => { test("verifies the raw Gitea HMAC signature", () => {
const body = Buffer.from('{"action":"created"}'); const body = Buffer.from('{"action":"created"}');
const signature = createHmac("sha256", "secret").update(body).digest("hex"); const signature = createHmac("sha256", "secret").update(body).digest("hex");