diff --git a/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/tests/errors.test.ts index db34cb3a908d..f03a611e9592 100644 --- a/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/tests/errors.test.ts @@ -33,7 +33,13 @@ test('Sends client-side error to Sentry', async ({ page }) => { test('Sends server-side function error to Sentry', async ({ page }) => { const errorEventPromise = waitForError('tanstackstart-react-cloudflare', 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(`/`); @@ -62,7 +68,12 @@ test('Sends server-side function error to Sentry', async ({ page }) => { test('Sends API route error to Sentry', async ({ page }) => { const errorEventPromise = waitForError('tanstackstart-react-cloudflare', 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(`/`);