diff --git a/lib/services/errors/glitchtip-error-reporting-service.ts b/lib/services/errors/glitchtip-error-reporting-service.ts index ae4de333..98069a03 100644 --- a/lib/services/errors/glitchtip-error-reporting-service.ts +++ b/lib/services/errors/glitchtip-error-reporting-service.ts @@ -56,6 +56,11 @@ export class GlitchtipErrorReportingService implements ErrorReportingService { tracesSampleRate: this.options.tracesSampleRate ?? 0.1, replaysOnErrorSampleRate: 1.0, replaysSessionSampleRate: 0.1, + ignoreErrors: [ + 'ChunkLoadError', + 'Failed to fetch dynamically imported module', + 'Failed to find Server Action', + ], }); } return Sentry; diff --git a/package.json b/package.json index 4ed96370..93220167 100644 --- a/package.json +++ b/package.json @@ -116,7 +116,7 @@ "prepare": "husky", "preinstall": "npx only-allow pnpm" }, - "version": "2.3.31", + "version": "2.3.32", "pnpm": { "onlyBuiltDependencies": [ "@parcel/watcher", diff --git a/tests/glitchtip-error-reporting.test.ts b/tests/glitchtip-error-reporting.test.ts new file mode 100644 index 00000000..c8a4c756 --- /dev/null +++ b/tests/glitchtip-error-reporting.test.ts @@ -0,0 +1,47 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { GlitchtipErrorReportingService } from '../lib/services/errors/glitchtip-error-reporting-service'; + +// Mock the LoggerService +const mockLogger = { + child: vi.fn().mockReturnThis(), + info: vi.fn(), + error: vi.fn(), + warn: vi.fn(), + debug: vi.fn(), +} as any; + +const mockSentryInit = vi.fn(); + +vi.mock('@sentry/nextjs', () => ({ + init: (...args: any[]) => mockSentryInit(...args), + captureException: vi.fn(), + captureMessage: vi.fn(), +})); + +describe('GlitchtipErrorReportingService', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('should ignore version drift errors (ChunkLoadError and Server Action) in Sentry config', async () => { + // Simulate window to force client-side init behavior instantly + const originalWindow = global.window; + global.window = { + requestIdleCallback: (cb: Function) => cb(), + } as any; + + const service = new GlitchtipErrorReportingService({ enabled: true }, mockLogger); + + // Give the dynamic import a moment to resolve + await new Promise((resolve) => setTimeout(resolve, 50)); + + expect(mockSentryInit).toHaveBeenCalledOnce(); + const initCallArgs = mockSentryInit.mock.calls[0][0]; + + expect(initCallArgs.ignoreErrors).toBeDefined(); + expect(initCallArgs.ignoreErrors).toContain('ChunkLoadError'); + expect(initCallArgs.ignoreErrors).toContain('Failed to find Server Action'); + + global.window = originalWindow; + }); +});