Skip to content

Commit de2a2e0

Browse files
mydeaclaude
andauthored
test(tanstackstart): Deterministically match the server-side error event (#22137)
The tanstackstart server-function error test flaked: it asserted the error's mechanism is `auto.middleware.tanstackstart.server_function`, but occasionally received `auto.browser.global_handlers.onunhandledrejection` instead. _Root cause_: the thrown error propagates back to the client over the server-function RPC and is captured a second time on the client as an `onunhandledrejection` with the **same message**. The `waitForError` predicate matched on message only, so it raced the two events and sometimes resolved with the client-side duplicate. The predicate now also matches the server mechanism, so the correct server-side event is always selected. The same latent race exists in the API-route test (identical message-only predicate + specific-mechanism assertion), so that predicate is hardened the same way. Fixes #21912 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c845ae9 commit de2a2e0

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

  • dev-packages/e2e-tests/test-applications/tanstackstart-react/tests

dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ test('Sends client-side error to Sentry with auto-instrumentation', async ({ pag
4343

4444
test('Sends server-side function error to Sentry with auto-instrumentation', async ({ page }) => {
4545
const errorEventPromise = waitForError('tanstackstart-react', errorEvent => {
46-
return errorEvent?.exception?.values?.[0]?.value === 'Sentry Server Function Test Error';
46+
// The thrown error propagates back to the client over the server-function RPC and is also
47+
// captured there as an `onunhandledrejection` with the same message. Match on the server-function
48+
// mechanism so we deterministically pick the server-side event instead of racing the client one.
49+
return (
50+
errorEvent?.exception?.values?.[0]?.value === 'Sentry Server Function Test Error' &&
51+
errorEvent?.exception?.values?.[0]?.mechanism?.type === 'auto.middleware.tanstackstart.server_function'
52+
);
4753
});
4854

4955
await page.goto(`/`);
@@ -74,7 +80,12 @@ test('Sends server-side function error to Sentry with auto-instrumentation', asy
7480

7581
test('Sends API route error to Sentry with auto-instrumentation', async ({ page }) => {
7682
const errorEventPromise = waitForError('tanstackstart-react', errorEvent => {
77-
return errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error';
83+
// As with the server-function test, guard against a same-message client-side duplicate by
84+
// matching the server request mechanism, so we always assert against the server-side event.
85+
return (
86+
errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error' &&
87+
errorEvent?.exception?.values?.[0]?.mechanism?.type === 'auto.middleware.tanstackstart.request'
88+
);
7889
});
7990

8091
await page.goto(`/`);

0 commit comments

Comments
 (0)