From ae3913be6be94fa73dc6af2c6ca1591f387fb370 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 9 Jul 2026 12:45:36 +0200 Subject: [PATCH] test(tanstackstart): Deterministically match the server-side error event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server-function and API-route error tests waited for the error event by message only. But the thrown error also propagates back to the client (over the server-function RPC / fetch) and is captured there as an `onunhandledrejection` with the same message, so `waitForError` raced the two and sometimes resolved with the client-side duplicate — failing the mechanism assertion (`auto.browser.global_handlers.onunhandledrejection` instead of the expected server mechanism). Match the server mechanism in the predicate so the correct server-side event is always selected. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../tanstackstart-react/tests/errors.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts index 235ae6af5dca..9447409b6cf9 100644 --- a/dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts @@ -43,7 +43,13 @@ test('Sends client-side error to Sentry with auto-instrumentation', async ({ pag test('Sends server-side function error to Sentry with auto-instrumentation', async ({ page }) => { const errorEventPromise = waitForError('tanstackstart-react', errorEvent => { - return errorEvent?.exception?.values?.[0]?.value === 'Sentry Server Function Test Error'; + // The thrown error propagates back to the client over the server-function RPC and is also + // captured there as an `onunhandledrejection` with the same message. Match on the server-function + // mechanism so we deterministically pick the server-side event instead of racing the client one. + return ( + errorEvent?.exception?.values?.[0]?.value === 'Sentry Server Function Test Error' && + errorEvent?.exception?.values?.[0]?.mechanism?.type === 'auto.middleware.tanstackstart.server_function' + ); }); await page.goto(`/`); @@ -74,7 +80,12 @@ test('Sends server-side function error to Sentry with auto-instrumentation', asy test('Sends API route error to Sentry with auto-instrumentation', async ({ page }) => { const errorEventPromise = waitForError('tanstackstart-react', errorEvent => { - return errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error'; + // As with the server-function test, guard against a same-message client-side duplicate by + // matching the server request mechanism, so we always assert against the server-side event. + return ( + errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error' && + errorEvent?.exception?.values?.[0]?.mechanism?.type === 'auto.middleware.tanstackstart.request' + ); }); await page.goto(`/`);