From cc284c430725b81f5ba8d7b25394da84c507613d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 25 Oct 2026 00:51:32 +0200 Subject: [PATCH] fix(jobs): log a failed preload report instead of swallowing it The sweep keeps going when reporting a load failure itself throws, and now says so on stderr; the error-level guard refuses a silent catch in src/lib/jobs. The preload test reads the worker source through readSource with anchors. --- .../registry/__tests__/preload-handlers.test.ts | 13 ++++++------- src/lib/jobs/registry/register.ts | 9 +++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib/jobs/registry/__tests__/preload-handlers.test.ts b/src/lib/jobs/registry/__tests__/preload-handlers.test.ts index 6f73883e9..cbb8a425a 100644 --- a/src/lib/jobs/registry/__tests__/preload-handlers.test.ts +++ b/src/lib/jobs/registry/__tests__/preload-handlers.test.ts @@ -7,9 +7,6 @@ * with nobody told at deploy time. The worker now loads every handler once in * the background after binding and reports each failure by queue name. */ -import { readFileSync } from "node:fs"; -import { join } from "node:path"; - import { beforeEach, describe, expect, it, vi } from "vitest"; import type { Job, PgBoss } from "pg-boss"; @@ -47,6 +44,8 @@ import { emitSignal } from "@/lib/logging/signal"; import { reportWorkerError } from "@/lib/jobs/report-worker-error"; import { reportHandlerLoadFailure } from "@/lib/jobs/run-job"; +import { readSource } from "@/__tests__/helpers/source-files"; + import type { JobDefinition, JobGroup } from "../define-job"; import { preloadHandlers, @@ -156,10 +155,10 @@ describe("preloading the job handlers at worker boot", () => { }); it("is started by the worker after binding, without holding up the boot", () => { - const source = readFileSync( - join(process.cwd(), "src/lib/jobs/reminder-worker.ts"), - "utf8", - ); + const source = readSource("src/lib/jobs/reminder-worker.ts", [ + "registry.registerAllJobGroups(", + "void registry.preloadHandlers(bound)", + ]); const register = source.indexOf("registry.registerAllJobGroups("); const preload = source.indexOf("void registry.preloadHandlers(bound)"); expect(register).toBeGreaterThan(-1); diff --git a/src/lib/jobs/registry/register.ts b/src/lib/jobs/registry/register.ts index c11052fdb..f53205381 100644 --- a/src/lib/jobs/registry/register.ts +++ b/src/lib/jobs/registry/register.ts @@ -208,8 +208,13 @@ export async function preloadHandlers( failed.push(queue); try { await report(queue, error); - } catch { - // The report is the last line of defence; it must not stop the sweep. + } catch (reportError) { + // The report failing must not stop the sweep; say so on stderr. + workerLog( + "error", + `[registry] reporting the load failure of ${queue} failed`, + reportError, + ); } } }