diff --git a/.changeset/log-visit-maintenance-failures.md b/.changeset/log-visit-maintenance-failures.md new file mode 100644 index 0000000..dc3f763 --- /dev/null +++ b/.changeset/log-visit-maintenance-failures.md @@ -0,0 +1,5 @@ +--- +'@goto/worker': patch +--- + +Log failed visit maintenance attempts without exposing error details or changing retry behavior. diff --git a/apps/worker/src/workflows/maintain-visits.test.ts b/apps/worker/src/workflows/maintain-visits.test.ts index 20a3783..368ed37 100644 --- a/apps/worker/src/workflows/maintain-visits.test.ts +++ b/apps/worker/src/workflows/maintain-visits.test.ts @@ -1,6 +1,7 @@ import { loadConfig } from '@goto/config'; import { afterEach, expect, test, vi } from 'vitest'; import type { WorkerContext } from '../services/context.js'; +import { logger } from '../services/logger.js'; import { maintainVisits } from '../services/maintain-visits.js'; import { runVisitMaintenance, type VisitMaintenanceStep } from './maintain-visits.js'; @@ -64,3 +65,16 @@ test('zero retention keeps scheduled hit accounting with the same durable jitter expect(sleep).toHaveBeenCalledOnce(); expect(maintainVisits).toHaveBeenCalledExactlyOnceWith(ctx); }); + +test('logs a failed maintenance attempt without exposing error details or swallowing the failure', async () => { + const failure = new Error('Private storage details'); + vi.mocked(maintainVisits).mockRejectedValueOnce(failure); + const log = vi.spyOn(logger, 'error').mockImplementation(() => undefined); + try { + const { step } = steps(); + await expect(runVisitMaintenance(context(), { scheduled: true }, step)).rejects.toBe(failure); + expect(log).toHaveBeenCalledExactlyOnceWith('Visit maintenance failed'); + } finally { + log.mockRestore(); + } +}); diff --git a/apps/worker/src/workflows/maintain-visits.ts b/apps/worker/src/workflows/maintain-visits.ts index dad614a..6b9e8bf 100644 --- a/apps/worker/src/workflows/maintain-visits.ts +++ b/apps/worker/src/workflows/maintain-visits.ts @@ -1,6 +1,7 @@ import { randomInt } from 'node:crypto'; import type { OpenWorkflow } from 'openworkflow'; import type { WorkerContext } from '../services/context.js'; +import { logger } from '../services/logger.js'; import { maintainVisits } from '../services/maintain-visits.js'; import { visitMaintenance, type VisitMaintenanceInput } from './specs.js'; @@ -21,8 +22,13 @@ export async function runVisitMaintenance( const duration: `${number}s` = `${seconds}s`; await step.sleep('retention-jitter', duration); } - function maintain(): Promise { - return maintainVisits(context); + async function maintain(): Promise { + try { + await maintainVisits(context); + } catch (error) { + logger.error('Visit maintenance failed'); + throw error; + } } // Preserve the durable step identity used by already-queued maintenance runs. await step.run({ name: 'retain-visits' }, maintain);